first commit
This commit is contained in:
40
weather.py
Normal file
40
weather.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import aiohttp
|
||||
|
||||
async def get_daily_weather_summary(lat: float, lon: float) -> str:
|
||||
# Добавили current=temperature_2m для получения текущей температуры
|
||||
url = (
|
||||
f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}"
|
||||
f"¤t=temperature_2m"
|
||||
f"&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_max"
|
||||
f"&timezone=auto&forecast_days=1"
|
||||
)
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as response:
|
||||
if response.status != 200:
|
||||
return "Не удалось получить данные о погоде."
|
||||
|
||||
data = await response.json()
|
||||
|
||||
current = data.get("current", {})
|
||||
daily = data.get("daily", {})
|
||||
|
||||
if not daily or not current:
|
||||
return "Ошибка парсинга данных о погоде."
|
||||
|
||||
current_temp = current.get("temperature_2m", "N/A")
|
||||
temp_max = daily["temperature_2m_max"][0]
|
||||
temp_min = daily["temperature_2m_min"][0]
|
||||
precip_prob = daily["precipitation_probability_max"][0]
|
||||
|
||||
temp_diff = round(temp_max - temp_min, 1)
|
||||
|
||||
summary = (
|
||||
f"🌤 **Погода на сегодня:**\n\n"
|
||||
f"🌡 **Сейчас:** {current_temp}°C\n"
|
||||
f"📊 **Дневная норма:** от {temp_min}°C до {temp_max}°C\n"
|
||||
f"📉 **Перепад температур за день:** {temp_diff}°C\n"
|
||||
f"🌧 **Макс. вероятность осадков:** {precip_prob}%\n\n"
|
||||
f"Одевайтесь по погоде и хорошего дня!"
|
||||
)
|
||||
return summary
|
||||
Reference in New Issue
Block a user