backend/passfinder/events/services.py

22 lines
588 B
Python
Raw Normal View History

2023-05-27 18:50:14 +03:00
import requests
from django.conf import settings
api_url = "https://api.weather.yandex.ru/v2/forecast"
2023-05-28 13:42:20 +03:00
def get_position_weather(lat: float, lon: float) -> list[(str, str)]:
url = api_url + f"?lat={lat}&lon={lon}&lang=ru_RU&limit=3&hours=false"
2023-05-27 18:50:14 +03:00
response = requests.get(
url=url, headers={"X-Yandex-API-Key": settings.YANDEX_TOKEN}
)
2023-05-28 13:42:20 +03:00
2023-05-27 18:50:14 +03:00
if response.status_code == 200:
data = response.json()
2023-05-28 13:42:20 +03:00
days = []
for d in data["forecasts"]:
days.append((d["date"], d["parts"]["day_short"]["condition"]))
return days
return []