Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
|
| 144 |
-
|
| 145 |
|
| 146 |
-
|
| 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:
|