aromidvar1355 commited on
Commit
a1a6d07
·
verified ·
1 Parent(s): 65cbfaa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -4
app.py CHANGED
@@ -3,19 +3,22 @@ import pandas as pd
3
  import requests
4
  import datetime
5
  import plotly.express as px
 
6
  import folium
7
  from streamlit_folium import folium_static
8
  import numpy as np
9
  import time
10
  from datetime import datetime, timedelta
11
 
12
- # Page configuration
13
- st.set_page_config(layout="wide", page_title="Environmental Data Dashboard")
14
 
15
- # API Keys
16
  OPENWEATHER_API_KEY = "c6c267b301a145ddec9b381e7d87a5af"
17
  STORMGLASS_API_KEY = "bcabf6a8-0641-11f0-a4a9-0242ac130003-bcabf72a-0641-11f0-a4a9-0242ac130003"
18
 
 
 
 
 
19
  # Sidebar
20
  st.sidebar.title("Environmental Data Dashboard")
21
  st.sidebar.info("Select a data source and input parameters to retrieve environmental data.")
@@ -47,6 +50,41 @@ def fetch_openweather_forecast(lat, lon):
47
  st.error(f"Error fetching OpenWeather forecast data: {response.status_code}")
48
  return None
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # OpenWeather UI
51
  if data_source == "Weather":
52
  st.title("OpenWeather Data")
@@ -154,7 +192,7 @@ if data_source == "Weather":
154
  st.write(f"Conditions: {forecast['description']}")
155
  st.write(f"Humidity: {forecast['humidity']}% | Wind: {forecast['wind_speed']} m/s")
156
 
157
- # Rest of the code remains the same as in the original script (Stormglass section)
158
  # Stormglass UI
159
  if data_source == "Marine":
160
  st.title("Stormglass Marine & Weather Data")
 
3
  import requests
4
  import datetime
5
  import plotly.express as px
6
+ import json
7
  import folium
8
  from streamlit_folium import folium_static
9
  import numpy as np
10
  import time
11
  from datetime import datetime, timedelta
12
 
 
 
13
 
14
+ # api keys
15
  OPENWEATHER_API_KEY = "c6c267b301a145ddec9b381e7d87a5af"
16
  STORMGLASS_API_KEY = "bcabf6a8-0641-11f0-a4a9-0242ac130003-bcabf72a-0641-11f0-a4a9-0242ac130003"
17
 
18
+ # Page configuration
19
+ st.set_page_config(layout="wide", page_title="Environmental Data Dashboard")
20
+
21
+
22
  # Sidebar
23
  st.sidebar.title("Environmental Data Dashboard")
24
  st.sidebar.info("Select a data source and input parameters to retrieve environmental data.")
 
50
  st.error(f"Error fetching OpenWeather forecast data: {response.status_code}")
51
  return None
52
 
53
+ # Function to fetch Stormglass data
54
+ def fetch_stormglass_data(lat, lng, start_date, end_date, params=None):
55
+ base_url = "https://api.stormglass.io/v2/weather/point"
56
+
57
+ if params is None:
58
+ params = [
59
+ 'waveHeight', 'wavePeriod', 'waveDirection',
60
+ 'windSpeed', 'windDirection', 'airTemperature',
61
+ 'waterTemperature', 'seaLevel', 'humidity',
62
+ 'precipitation', 'visibility', 'currentSpeed',
63
+ 'currentDirection'
64
+ ]
65
+
66
+ headers = {
67
+ 'Authorization': STORMGLASS_API_KEY
68
+ }
69
+
70
+ request_params = {
71
+ 'lat': lat,
72
+ 'lng': lng,
73
+ 'params': ','.join(params),
74
+ 'start': start_date.isoformat(),
75
+ 'end': end_date.isoformat()
76
+ }
77
+
78
+ response = requests.get(base_url, headers=headers, params=request_params)
79
+
80
+ if response.status_code == 200:
81
+ data = response.json()
82
+ return data
83
+ else:
84
+ st.error(f"Error fetching Stormglass data: {response.status_code} - {response.text}")
85
+ return None
86
+
87
+
88
  # OpenWeather UI
89
  if data_source == "Weather":
90
  st.title("OpenWeather Data")
 
192
  st.write(f"Conditions: {forecast['description']}")
193
  st.write(f"Humidity: {forecast['humidity']}% | Wind: {forecast['wind_speed']} m/s")
194
 
195
+
196
  # Stormglass UI
197
  if data_source == "Marine":
198
  st.title("Stormglass Marine & Weather Data")