aromidvar1355 commited on
Commit
7eecc0f
·
verified ·
1 Parent(s): 46b5e63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
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 HTTPError for bad responses
39
- return response.json()
40
- except requests.exceptions.RequestException as e:
41
- st.error(f"Error fetching OpenWeather data: {e}")
42
- return None
 
 
 
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."""