import asyncio
import logging
import python_weather
from config import TOKEN2
from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.types import Message
bot = Bot(TOKEN2)
dp = Dispatcher()
async def main():
await dp.start_polling(bot)
@dp.message()
async def get_weather(message: Message):
async with python_weather.Client(unit=python_weather.METRIC) as client:
try:
weather = await client.get(message.text)
temperature = weather.current.temperature
response_message = f"Текущая температура в {message.text}: {temperature}°C"
await message.answer(response_message)
except Exception as e:
await message.answer("Не удалось получить данные о погоде.")
if __name__ == '__main__':
asyncio.run(main())