aromidvar1355 commited on
Commit
27dcee1
·
verified ·
1 Parent(s): 3b44d77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -18
app.py CHANGED
@@ -30,25 +30,16 @@ 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
-
34
- # Ensure datetime_input is timezone-aware
35
- if datetime_input.tzinfo is None:
36
- # Localize datetime input to UTC
37
- datetime_input = pytz.utc.localize(datetime_input)
38
-
39
- # Convert to Unix timestamp
40
- timestamp = int(datetime_input.timestamp())
41
-
42
- # Construct the URL for the API call
43
- url = f"https://api.openweathermap.org/data/3.0/onecall/timemachine?lat={lat}&lon={lon}&dt={timestamp}&appid={OPENWEATHER_API_KEY}&units=metric"
44
 
45
- try:
46
- response = requests.get(url)
47
- response.raise_for_status() # Raise HTTPError for bad responses
48
- return response.json()
49
- except requests.exceptions.RequestException as e:
50
- st.error(f"Error fetching OpenWeather data: {e}")
51
- return None
52
 
53
  def fetch_openweather_forecast(lat, lon):
54
  """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
 
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."""