Skip to content

Commit 77ab00b

Browse files
committed
merge conflicts
2 parents 103fdbb + 36c91ce commit 77ab00b

File tree

3 files changed

+48
-24
lines changed

3 files changed

+48
-24
lines changed

help.txt

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Usage:
22

33
$ curl localhost:8000 # current location
4-
$ curl localhost:8000?args=loc=new_york # surf report in New new_york
4+
$ curl localhost:8000?loc=new_york # surf report in New York
55

66
Supported location types:
77

@@ -18,26 +18,34 @@ Units:
1818

1919
Arguments:
2020

21-
location / loc #Specify the location of your forecast
22-
forecast / fc # Number of forecast days. Max = 7, default = 0
23-
hide_wave / hw # Hide the default wave art
24-
show_large_wave / slw # Show the large wave art
25-
hide_uv / huv # Hide uv index
26-
hide_height / hh # Hide surf height
27-
hide_direction / hdir # Hide Swell direction
28-
hide_period / hp # Hide swell period
29-
hide_location / hl # Hide location
30-
hide_date / hdate # Hide date in forecast
31-
metric / m # Numbers in Metric units. Defaults to Imperial
32-
decimal / dec # Specify decimal points in output
33-
color / c # Choose color of wave art. Ex: color=light_blue
21+
location / loc # Specify the location of your forecast
22+
forecast / fc # Number of forecast days. Max = 7, default = 0
23+
hide_wave / hw # Hide the default wave art
24+
show_large_wave / slw # Show the large wave art
25+
show_air_temp / sat # Show the air temperature
26+
show_wind_speed / sws # Show the wind speed
27+
show_wind_direction / swd # Show the wind direction
28+
hide_uv / huv # Hide UV index
29+
hide_height / hh # Hide surf height
30+
hide_direction / hdir # Hide swell direction
31+
hide_period / hp # Hide swell period
32+
hide_location / hl # Hide location
33+
hide_date / hdate # Hide date in forecast
34+
metric / m # Numbers in Metric units. Defaults to Imperial
35+
decimal / dec # Specify decimal points in output
36+
color / c # Choose color of wave art. Ex: color=light_blue
37+
json / j # Output the data in JSON format. Must be the only argument
38+
gpt / g # Activates the GPT surf report. Change the GPT_PROMPT variable in .env to customize responses. Default = off
3439

3540
Color Options:
3641

37-
defualt, red, green, yellow, blue, purple, teal, light_blue
42+
default, red, green, yellow, blue, purple, teal, light_blue
3843

3944
Examples:
4045

4146
curl localhost:8000
42-
curl localhost:8000?args=location=new_york,hide_height,hide_wave,show_large_wave
43-
curl localhost:8000?args=fc=3,hdate,loc=trestles,c=light_blue
47+
curl localhost:8000?loc=new_york,hide_height,hide_wave,show_large_wave
48+
curl localhost:8000?fc=3,hdate,loc=trestles,c=light_blue
49+
curl localhost:8000?loc=malibu,show_air_temp,show_wind_speed,show_wind_direction
50+
curl localhost:8000?loc=nazare,json
51+
curl localhost:8000?loc=gold_coast,gpt,color=yellow

src/api.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ def forecast(lat, long, decimal, days=0):
159159
retry_session = retry(cache_session, retries=5, backoff_factor=0.2)
160160
openmeteo = openmeteo_requests.Client(session=retry_session)
161161

162-
url = "https://marine-api.open-meteo.com/v1/marine"
162+
# First URL is the marine API. Second is for general weather/UV index
163+
urls = (
164+
"https://marine-api.open-meteo.com/v1/marine",
165+
"https://api.open-meteo.com/v1/forecast",
166+
)
163167
params = {
164168
"latitude": lat,
165169
"longitude": long,
@@ -172,9 +176,14 @@ def forecast(lat, long, decimal, days=0):
172176
"timezone": "auto",
173177
"forecast_days": days,
174178
}
175-
responses = openmeteo.weather_api(url, params=params)
179+
180+
params_uv = {"latitude": lat, "longitude": long, "daily": "uv_index_max"}
181+
182+
responses = openmeteo.weather_api(urls[0], params=params)
183+
responses_uv = openmeteo.weather_api(urls[1], params=params_uv)
176184

177185
response = responses[0]
186+
response_uv = responses_uv[0]
178187

179188
daily_height_max = helper.round_decimal(
180189
response.Daily().Variables(0).ValuesAsNumpy(), decimal
@@ -186,6 +195,10 @@ def forecast(lat, long, decimal, days=0):
186195
response.Daily().Variables(2).ValuesAsNumpy(), decimal
187196
)
188197

198+
daily_uv_index_max = helper.round_decimal(
199+
response_uv.Daily().Variables(0).ValuesAsNumpy(), decimal
200+
)
201+
189202
daily_data = {
190203
"date": pd.date_range(
191204
start=pd.to_datetime(response.Daily().Time(), unit="s", utc=True),
@@ -194,12 +207,12 @@ def forecast(lat, long, decimal, days=0):
194207
inclusive="left",
195208
)
196209
}
197-
198210
return [
199211
daily_height_max,
200212
daily_direction_dominant,
201213
daily_period_max,
202214
daily_data["date"],
215+
daily_uv_index_max,
203216
]
204217

205218

src/helper.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def print_forecast(ocean, forecast):
150150
print("Wave Direction: ", day[1])
151151
if int(ocean["show_period"]) == 1:
152152
print("Wave Period: ", day[2])
153+
if int(ocean["show_uv"]) == 1:
154+
print("UV Index: ", day[4])
153155
print("\n")
154156

155157

@@ -250,16 +252,17 @@ def forecast_to_json(data, decimal):
250252
"""
251253
Takes forecast() as input and returns it in JSON format
252254
"""
253-
surf_height, swell_direction, swell_period, dates = data
255+
surf_height, swell_direction, swell_period, dates, uv_index = data
254256

255257
# Formatting into JSON
256258
forecasts = []
257259
for i in range(len(dates)):
258260
forecast = {
259261
"date": str(dates[i].date()),
260-
"height": round(float(surf_height[i]), decimal),
261-
"direction": round(float(swell_direction[i]), decimal),
262-
"period": round(float(swell_period[i]), decimal),
262+
"surf height": round(float(surf_height[i]), decimal),
263+
"swell direction": round(float(swell_direction[i]), decimal),
264+
"swell period": round(float(swell_period[i]), decimal),
265+
"uv index": round(float(uv_index[i]), decimal),
263266
}
264267
forecasts.append(forecast)
265268

0 commit comments

Comments
 (0)