Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,16 +30,18 @@ data_source = st.sidebar.selectbox(
|
|
| 30 |
# --- API CALLING FUNCTIONS ---
|
| 31 |
def fetch_openweather_data(lat, lon, datetime_input):
|
| 32 |
"""Fetches historical weather data from OpenWeather's One Call API."""
|
| 33 |
-
# Construct the URL for the API call
|
| 34 |
url = f"https://api.openweathermap.org/data/3.0/onecall/timemachine?lat={lat}&lon={lon}&dt={int(datetime_input.timestamp())}&appid={OPENWEATHER_API_KEY}&units=metric"
|
| 35 |
-
|
| 36 |
try:
|
| 37 |
-
response = requests.get(url)
|
| 38 |
-
response.raise_for_status() # Raise
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def fetch_openweather_forecast(lat, lon):
|
| 45 |
"""Fetches 7-day weather forecast data from OpenWeather's One Call API."""
|
|
|
|
| 30 |
# --- API CALLING FUNCTIONS ---
|
| 31 |
def fetch_openweather_data(lat, lon, datetime_input):
|
| 32 |
"""Fetches historical weather data from OpenWeather's One Call API."""
|
| 33 |
+
# Construct the URL for the API call
|
| 34 |
url = f"https://api.openweathermap.org/data/3.0/onecall/timemachine?lat={lat}&lon={lon}&dt={int(datetime_input.timestamp())}&appid={OPENWEATHER_API_KEY}&units=metric"
|
|
|
|
| 35 |
try:
|
| 36 |
+
response = requests.get(url) # Make the API call
|
| 37 |
+
response.raise_for_status() # Raise an error for bad responses
|
| 38 |
+
data = response.json() # Parse JSON response
|
| 39 |
+
return data
|
| 40 |
+
except requests.exceptions.HTTPError as http_err:
|
| 41 |
+
st.error(f"HTTP error occurred: {http_err}")
|
| 42 |
+
except Exception as err:
|
| 43 |
+
st.error(f"An error occurred: {err}")
|
| 44 |
+
|
| 45 |
|
| 46 |
def fetch_openweather_forecast(lat, lon):
|
| 47 |
"""Fetches 7-day weather forecast data from OpenWeather's One Call API."""
|