aromidvar1355 commited on
Commit
c51b0e8
·
verified ·
1 Parent(s): 41598ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -35
app.py CHANGED
@@ -96,54 +96,55 @@ def fetch_solunar_tide_data(lat, lon, datetime_input):
96
 
97
  # --- MAIN APPLICATION LOGIC ---
98
  def main():
99
- st.title("OpenWeather Data")
 
100
 
101
- col1, col2 = st.columns(2)
102
 
103
- with col1:
104
- st.subheader("Location and Time Settings")
105
 
106
- # Latitude and Longitude inputs
107
- lat = st.number_input("Latitude", value=25.7617, step=0.001, format="%.4f")
108
- lon = st.number_input("Longitude", value=-80.1918, step=0.001, format="%.4f")
109
 
110
- # Manage session state for date and time inputs
111
- if 'datetime_input' not in st.session_state:
112
- # Initialize with current date and time if not already present
113
- st.session_state['datetime_input'] = datetime.now()
114
 
115
- # Split the stored datetime into date and time components
116
- datetime_input = st.session_state['datetime_input']
117
- input_date = datetime_input.date() # Use the date part
118
- input_time = datetime_input.time() # Use the time part
119
 
120
- # Allow user to set new date and time
121
- input_date = st.date_input("Date", value=input_date)
122
- input_time = st.time_input("Time", value=input_time)
123
 
124
- # Combine date and time into a datetime object
125
- datetime_input = datetime.combine(input_date, input_time)
126
- st.session_state['datetime_input'] = datetime_input # Store the datetime in the session state
127
 
128
- if st.button("Get Current Weather"):
129
- with st.spinner("Fetching data..."):
130
- data = fetch_openweather_data(lat, lon, datetime_input)
131
 
132
- if data and 'data' in data:
133
- current_weather_data = data['data']
134
- if current_weather_data:
135
- current = current_weather_data[0]
136
 
137
- # Convert and format sunrise and sunset
138
- timezone = data.get('timezone', 'UTC')
139
- tz = pytz.timezone(timezone)
140
 
141
- sunrise_time = datetime.fromtimestamp(current['sunrise'], tz).strftime('%Y-%m-%d %H:%M:%S')
142
- sunset_time = datetime.fromtimestamp(current['sunset'], tz).strftime('%Y-%m-%d %H:%M:%S')
143
 
144
- st.subheader(f"Weather at {lat}, {lon} on {datetime_input}")
145
 
146
- weather_col1, weather_col2 = st.columns(2)
147
 
148
 
149
  with weather_col1:
 
96
 
97
  # --- MAIN APPLICATION LOGIC ---
98
  def main():
99
+ if data_source == "Weather Data":
100
+ st.title("OpenWeather Data")
101
 
102
+ col1, col2 = st.columns(2)
103
 
104
+ with col1:
105
+ st.subheader("Location and Time Settings")
106
 
107
+ # Latitude and Longitude inputs
108
+ lat = st.number_input("Latitude", value=25.7617, step=0.001, format="%.4f")
109
+ lon = st.number_input("Longitude", value=-80.1918, step=0.001, format="%.4f")
110
 
111
+ # Manage session state for date and time inputs
112
+ if 'datetime_input' not in st.session_state:
113
+ # Initialize with current date and time if not already present
114
+ st.session_state['datetime_input'] = datetime.now()
115
 
116
+ # Split the stored datetime into date and time components
117
+ datetime_input = st.session_state['datetime_input']
118
+ input_date = datetime_input.date() # Use the date part
119
+ input_time = datetime_input.time() # Use the time part
120
 
121
+ # Allow user to set new date and time
122
+ input_date = st.date_input("Date", value=input_date)
123
+ input_time = st.time_input("Time", value=input_time)
124
 
125
+ # Combine date and time into a datetime object
126
+ datetime_input = datetime.combine(input_date, input_time)
127
+ st.session_state['datetime_input'] = datetime_input # Store the datetime in the session state
128
 
129
+ if st.button("Get Current Weather"):
130
+ with st.spinner("Fetching data..."):
131
+ data = fetch_openweather_data(lat, lon, datetime_input)
132
 
133
+ if data and 'data' in data:
134
+ current_weather_data = data['data']
135
+ if current_weather_data:
136
+ current = current_weather_data[0]
137
 
138
+ # Convert and format sunrise and sunset
139
+ timezone = data.get('timezone', 'UTC')
140
+ tz = pytz.timezone(timezone)
141
 
142
+ sunrise_time = datetime.fromtimestamp(current['sunrise'], tz).strftime('%Y-%m-%d %H:%M:%S')
143
+ sunset_time = datetime.fromtimestamp(current['sunset'], tz).strftime('%Y-%m-%d %H:%M:%S')
144
 
145
+ st.subheader(f"Weather at {lat}, {lon} on {datetime_input}")
146
 
147
+ weather_col1, weather_col2 = st.columns(2)
148
 
149
 
150
  with weather_col1: