UPDATE
This commit is contained in:
+30
-4
@@ -5,6 +5,7 @@
|
||||
import logging
|
||||
from datetime import date, timedelta
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
|
||||
@@ -42,10 +43,35 @@ def fetch_weather_from_api(latitude: float, longitude: float) -> dict | None:
|
||||
}
|
||||
}
|
||||
"""
|
||||
# TODO: اتصال واقعی به API هواشناسی
|
||||
# api_url = settings.WEATHER_API_BASE_URL
|
||||
# api_key = settings.WEATHER_API_KEY
|
||||
return None
|
||||
params = {
|
||||
"latitude": latitude,
|
||||
"longitude": longitude,
|
||||
"forecast_days": 7,
|
||||
"timezone": "auto",
|
||||
"daily": [
|
||||
"temperature_2m_max",
|
||||
"temperature_2m_min",
|
||||
"temperature_2m_mean",
|
||||
"precipitation_sum",
|
||||
"precipitation_probability_max",
|
||||
"relative_humidity_2m_mean",
|
||||
"wind_speed_10m_max",
|
||||
"et0_fao_evapotranspiration",
|
||||
"weather_code",
|
||||
],
|
||||
}
|
||||
headers = {"accept": "application/json"}
|
||||
if settings.WEATHER_API_KEY:
|
||||
headers["Authorization"] = f"Bearer {settings.WEATHER_API_KEY}"
|
||||
|
||||
response = requests.get(
|
||||
settings.WEATHER_API_BASE_URL,
|
||||
params=params,
|
||||
headers=headers,
|
||||
timeout=60,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
def parse_weather_response(data: dict) -> list[dict]:
|
||||
|
||||
Reference in New Issue
Block a user