diff --git a/docs/structure.md b/docs/structure.md index 031e1e3..7d5d775 100644 --- a/docs/structure.md +++ b/docs/structure.md @@ -28,6 +28,9 @@ More in-depth structure: . ├── compose.yaml ├── CONTRIBUTING.md +├── dist +│   ├── cli_surf-0.1.0-py3-none-any.whl +│   └── cli_surf-0.1.0.tar.gz ├── Dockerfile ├── docs │   ├── cheat_sheet.md @@ -73,6 +76,6 @@ More in-depth structure: ├── test_helper.py └── test_server.py -9 directories, 38 files +10 directories, 40 files ``` diff --git a/src/api.py b/src/api.py index 5eae1d2..641ef06 100644 --- a/src/api.py +++ b/src/api.py @@ -159,7 +159,11 @@ def forecast(lat, long, decimal, days=0): retry_session = retry(cache_session, retries=5, backoff_factor=0.2) openmeteo = openmeteo_requests.Client(session=retry_session) - url = "https://marine-api.open-meteo.com/v1/marine" + # First URL is the marine API. Second is for general weather/UV index + urls = ( + "https://marine-api.open-meteo.com/v1/marine", + "https://api.open-meteo.com/v1/forecast", + ) params = { "latitude": lat, "longitude": long, @@ -172,9 +176,14 @@ def forecast(lat, long, decimal, days=0): "timezone": "auto", "forecast_days": days, } - responses = openmeteo.weather_api(url, params=params) + + params_uv = {"latitude": lat, "longitude": long, "daily": "uv_index_max"} + + responses = openmeteo.weather_api(urls[0], params=params) + responses_uv = openmeteo.weather_api(urls[1], params=params_uv) response = responses[0] + response_uv = responses_uv[0] daily_height_max = helper.round_decimal( response.Daily().Variables(0).ValuesAsNumpy(), decimal @@ -186,6 +195,10 @@ def forecast(lat, long, decimal, days=0): response.Daily().Variables(2).ValuesAsNumpy(), decimal ) + daily_uv_index_max = helper.round_decimal( + response_uv.Daily().Variables(0).ValuesAsNumpy(), decimal + ) + daily_data = { "date": pd.date_range( start=pd.to_datetime(response.Daily().Time(), unit="s", utc=True), @@ -194,12 +207,12 @@ def forecast(lat, long, decimal, days=0): inclusive="left", ) } - return [ daily_height_max, daily_direction_dominant, daily_period_max, daily_data["date"], + daily_uv_index_max, ] diff --git a/src/helper.py b/src/helper.py index 01d1f77..2c18602 100644 --- a/src/helper.py +++ b/src/helper.py @@ -150,6 +150,8 @@ def print_forecast(ocean, forecast): print("Wave Direction: ", day[1]) if int(ocean["show_period"]) == 1: print("Wave Period: ", day[2]) + if int(ocean["show_uv"]) == 1: + print("UV Index: ", day[4]) print("\n") @@ -248,7 +250,7 @@ def forecast_to_json(data, decimal): """ Takes forecast() as input and returns it in JSON format """ - surf_height, swell_direction, swell_period, dates = data + surf_height, swell_direction, swell_period, dates, uv_index = data # Formatting into JSON forecasts = [] @@ -258,6 +260,7 @@ def forecast_to_json(data, decimal): "surf height": round(float(surf_height[i]), decimal), "swell direction": round(float(swell_direction[i]), decimal), "swell period": round(float(swell_period[i]), decimal), + "uv index": round(float(uv_index[i]), decimal), } forecasts.append(forecast)