-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
44 lines (32 loc) · 1.57 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import asyncio
import logging
from datetime import datetime
from aiogram import Bot, Dispatcher
from aiogram.types import Message
from aiogram.filters.command import Command
from config import config
from api import get_weather_by_city
bot = Bot(token=config.TOKEN)
dp = Dispatcher()
logging.basicConfig(level=logging.INFO)
@dp.message(Command('start'))
async def start(message: Message):
await message.answer('Привет, я могу рассказать тебе о погоде.\n'
'Просто отправь название своего города.')
@dp.message()
async def get_weather(message: Message):
weather = await get_weather_by_city(message.text)
if weather['cod'] == '404' and weather['message'] == 'city not found':
await message.answer('Город не найден.\n'
'Проверьте правильность написания.')
else:
city = message.text
await message.answer(f'🌇 Сейчас в городе {city} {weather["weather"][0]["description"]}.\n'
f'🌡 Температура: {round(weather["main"]["temp"])} °C.\n'
f'💨 Ветер: {round(weather["wind"]["speed"], 1)} м/c.\n'
f'💦 Влажность: {weather["main"]["humidity"]} %.\n'
f'🧭 Давление: {round(weather["main"]["pressure"] * 0.750062)} мм рт. ст.')
async def main():
await dp.start_polling(bot)
if __name__ == '__main__':
asyncio.run(main())