From 034223a52bc57d251a21868f8335101c8765eec0 Mon Sep 17 00:00:00 2001 From: Niken Date: Tue, 17 Mar 2026 20:30:46 +0300 Subject: [PATCH] =?UTF-8?q?It's=20version=200.7.1=20=D0=AF=20=D0=B4=D1=83?= =?UTF-8?q?=D0=BC=D0=B0=D1=8E=20=D1=8D=D1=82=D0=B0=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=D0=B4=D0=BD=D0=B0=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=82=D0=B0=D0=BA=20=D0=BA=D0=B0=D0=BA=20=D0=B8?= =?UTF-8?q?=D0=B7-=D0=B7=D0=B0=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=B8=20=D0=BD=D0=B8=D0=B7=D0=BA=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20=D0=B1=D1=8B=D0=BB=D0=BE?= =?UTF-8?q?=20=D0=BC=D0=BD=D0=BE=D0=B9=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B7=D0=B0=D0=B1=D1=80=D0=BE=D1=81=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B5=D0=B5=20=D0=BD=D0=B0=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=B5=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F,=20?= =?UTF-8?q?=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BD=D0=B5=20=D0=BD=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=D0=B3=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/weather/__init__.py | 9 +++++++++ addons/weather/api.py | 11 +++++++++++ addons/weather/handlers.py | 20 ++++++++++++++++++++ bot/core.py | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 addons/weather/__init__.py create mode 100644 addons/weather/api.py create mode 100644 addons/weather/handlers.py diff --git a/addons/weather/__init__.py b/addons/weather/__init__.py new file mode 100644 index 0000000..e0acb2f --- /dev/null +++ b/addons/weather/__init__.py @@ -0,0 +1,9 @@ +def register(dp, state, bot): + from . import handlers + + handlers.register_handlers(dp, state, bot) + + +def unregister(dp): + # Здесь можно удалить хендлеры, если нужно + dp.message_handlers.handlers.clear() diff --git a/addons/weather/api.py b/addons/weather/api.py new file mode 100644 index 0000000..f8c6e7f --- /dev/null +++ b/addons/weather/api.py @@ -0,0 +1,11 @@ +import requests + +def get_weather(city: str): + return requests.get(f"https://api.weatherapi.com/v1/current.json?key=becad22574854f91aea163009261703&q={city}&aqi=no").json() + +if __name__ == "__main__": + print(get_weather("Minsk")['location']['name']) + print(get_weather("Minsk")['current']['temp_c']) + print(get_weather("Minsk")['current']['condition']["text"]) + print(get_weather("Minsk")['current']['wind_kph']) + print(str(get_weather("Minsk")['current']['humidity'])+"%") \ No newline at end of file diff --git a/addons/weather/handlers.py b/addons/weather/handlers.py new file mode 100644 index 0000000..8f2acef --- /dev/null +++ b/addons/weather/handlers.py @@ -0,0 +1,20 @@ +from aiogram import Dispatcher, Bot +from aiogram.filters import Command +from aiogram.types import Message +from .api import get_weather + + +def register_handlers(dp: Dispatcher, state, bot: Bot): + @dp.message(Command("weather")) + async def weather(message: Message): + weather_data = get_weather("Minsk") + + await message.answer( + f"🌍 *Погода в городе {weather_data['location']['name']}*\n\n" + f"🌡 *Температура:* {weather_data['current']['temp_c']}°C\n" + f"☁️ *Состояние:* {weather_data['current']['condition']['text']}\n" + f"💨 *Ветер:* {weather_data['current']['wind_kph']} км/ч\n" + f"💧 *Влажность:* {weather_data['current']['humidity']}%\n\n" + f"📅 *Обновлено:* {weather_data['current']['last_updated']}", + parse_mode="Markdown" + ) \ No newline at end of file diff --git a/bot/core.py b/bot/core.py index 0e6f059..496cc9e 100644 --- a/bot/core.py +++ b/bot/core.py @@ -27,7 +27,7 @@ class TelegramBot: self.addons.load("send_message") self.addons.load("poll") self.addons.load("hello") - # self.addons.load("draw") + self.addons.load("weather") self.addons.load("gpt") self.addons.load("rule34") # self.addons.load("todo")