1
- import telebot
2
- import pyowm
3
- import Database
1
+ from pyowm .owm import OWM
2
+ from pyowm .weatherapi25 .observation import Observation
3
+ from telebot import TeleBot
4
+ from telebot .types import ReplyKeyboardMarkup
5
+ from Database import YAML
4
6
from config import *
5
7
6
- bot = telebot .TeleBot (telegram_key )
7
- owm = pyowm .OWM (weather_key )
8
- mgr = owm .weather_manager ()
8
+ MAX_LEN_OF_PLACE = 20
9
+
10
+ bot = TeleBot (telegram_key )
11
+ mgr = OWM (weather_key ).weather_manager ()
9
12
help_msg = "Команды:\n /place - Ввод названия города. \n /update - Обновление информации об погоде в текущем городе \n /current_place - Вывод текущего города. \n /help - Вывод справки по командам бота"
10
13
11
- keyboard = telebot . types . ReplyKeyboardMarkup (True , True )
14
+ keyboard = ReplyKeyboardMarkup (True , True )
12
15
keyboard .row ('/place' , '/update' ,'/current_place' ,'/help' )
13
16
14
- db = Database . YAML ()
17
+ db = YAML ()
15
18
16
19
@bot .message_handler (commands = ['start' ])
17
20
def start_message (message ):
@@ -49,7 +52,7 @@ def help_message(message):
49
52
def current_place (message ):
50
53
bot .send_message (message .chat .id , db .get_geolocation (message .chat .id ), reply_markup = keyboard )
51
54
52
- def output_data (observation ) :
55
+ def output_data (observation : Observation ) -> str :
53
56
w = observation .weather
54
57
answear = f'В городе { observation .location .name } { w .detailed_status } \n '
55
58
answear += f'Температура воздуха составляет { w .temperature ("celsius" )["temp" ]} °C\n '
@@ -60,8 +63,8 @@ def output_data(observation):
60
63
answear += f'Заход солнца: { w .sunset_time (timeformat = "iso" )} \n '
61
64
return answear
62
65
63
- def get_current_weather (place ) :
64
- if place == None or len (place ) > 20 :
66
+ def get_current_weather (place : str ) -> Observation or None :
67
+ if place == None or len (place ) > MAX_LEN_OF_PLACE :
65
68
return None
66
69
try :
67
70
observation = mgr .weather_at_place (place )
0 commit comments