From ed812686769145dfa59f7108cea9b0ad999597df Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Sat, 8 Jun 2024 15:18:21 -0700 Subject: [PATCH 01/17] added wind/air temp data! --- src/api.py | 44 +++++++++++++++++++++++++++++++++++++++++++- src/helper.py | 35 +++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/src/api.py b/src/api.py index 07b1b71..2d06e45 100644 --- a/src/api.py +++ b/src/api.py @@ -117,6 +117,42 @@ def ocean_information(lat, long, decimal, unit="imperial"): return [current_wave_height, current_wave_direction, current_wave_period] +def current_wind_temp(lat, long, decimal, temp_unit="fahrenheit"): + """ + Gathers the wind and temperature data + """ + # Setup the Open-Meteo API client with cache and retry on error + cache_session = requests_cache.CachedSession('.cache', expire_after = 3600) + retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2) + openmeteo = openmeteo_requests.Client(session = retry_session) + + # Make sure all required weather variables are listed here + # The order of variables in hourly or daily is important to assign them correctly below + url = "https://api.open-meteo.com/v1/forecast" + params = { + "latitude": lat, + "longitude": long, + "current": ["temperature_2m", "wind_speed_10m", "wind_direction_10m"], + "temperature_unit": temp_unit, + "wind_speed_unit": "mph", + "precipitation_unit": "inch" + } + responses = openmeteo.weather_api(url, params=params) + + # Process first location. Add a for-loop for multiple locations or weather models + response = responses[0] + + # Current values. The order of variables needs to be the same as requested. + current = response.Current() + current_temperature = round( + current.Variables(0).Value(), decimal) + current_wind_speed = round( + current.Variables(1).Value(), decimal) + current_wind_direction = round( + current.Variables(2).Value(), decimal) + + return current_temperature, current_wind_speed, current_wind_direction + def forecast(lat, long, decimal, days=0): """ @@ -184,6 +220,9 @@ def gather_data(lat, long, arguments): ) uv_index = get_uv(lat, long, arguments["decimal"], arguments["unit"]) + wind_temp = current_wind_temp(lat, long, arguments["decimal"]) + air_temp, wind_speed, wind_dir = wind_temp[0], wind_temp[1], wind_temp[2] + arguments["ocean_data"] = ocean_data arguments["uv_index"] = uv_index spot_forecast = forecast(lat, long, arguments["decimal"], 7) @@ -196,9 +235,12 @@ def gather_data(lat, long, arguments): "Long": long, "Location": arguments["city"], "Height": ocean_data[0], - "Direction": ocean_data[1], + "Swell Direction": ocean_data[1], "Period": ocean_data[2], "UV Index": uv_index, + "Air Temperature": air_temp, + "Wind Speed": wind_speed, + "Wind Direction": wind_dir, "Forecast": json_forecast, "Unit": arguments["unit"], } diff --git a/src/helper.py b/src/helper.py index c1452a2..027a6dd 100644 --- a/src/helper.py +++ b/src/helper.py @@ -27,6 +27,9 @@ def arguments_dictionary(lat, long, city, args): "show_period": 1, "show_city": 1, "show_date": 1, + "show_air_temp": 0, + "show_wind_speed": 0, + "show_wind_direction": 0, "json_output": 0, "unit": "imperial", "decimal": extract_decimal(args), @@ -68,6 +71,12 @@ def set_output_values(args, arguments): arguments["json_output"] = 1 if "gpt" in args or "g" in args: arguments["gpt"] = 1 + if "show_air_temp" in args or "sat" in args: + arguments["show_air_temp"] = 1 + if "show_wind_speed" in args or "sws" in args: + arguments["show_wind_speed"] = 1 + if "show_wind_direction" in args or "swd" in args: + arguments["show_wind_direction"] = 1 return arguments @@ -106,18 +115,24 @@ def print_location(city, show_city): print("\n") -def print_ocean_data(ocean_data_dict): +def print_ocean_data(arguments_dict, ocean_data_dict): """ Prints ocean data(height, wave direction, period, etc) """ - if int(ocean_data_dict["show_uv"]) == 1: - print("UV index: ", ocean_data_dict["uv_index"]) - if int(ocean_data_dict["show_height"]) == 1: - print("Wave Height: ", ocean_data_dict["ocean_data"][0]) - if int(ocean_data_dict["show_direction"]) == 1: - print("Wave Direction: ", ocean_data_dict["ocean_data"][1]) - if int(ocean_data_dict["show_period"]) == 1: - print("Wave Period: ", ocean_data_dict["ocean_data"][2]) + if int(arguments_dict["show_uv"]) == 1: + print("UV index: ", ocean_data_dict["UV Index"]) + if int(arguments_dict["show_height"]) == 1: + print("Wave Height: ", ocean_data_dict["Height"]) + if int(arguments_dict["show_direction"]) == 1: + print("Wave Direction: ", ocean_data_dict["Swell Direction"]) + if int(arguments_dict["show_period"]) == 1: + print("Wave Period: ", ocean_data_dict["Period"]) + if int(arguments_dict["show_air_temp"]) == 1: + print("Air Temp: ", ocean_data_dict["Air Temperature"]) + if int(arguments_dict["show_wind_speed"]) == 1: + print("Wind Speed: ", ocean_data_dict["Wind Speed"]) + if int(arguments_dict["show_wind_direction"]) == 1: + print("Wind Direction: ", ocean_data_dict["Wind Direction"]) def print_forecast(ocean, forecast): @@ -203,7 +218,7 @@ def print_outputs(city, data_dict, arguments, gpt_prompt, gpt_info): arguments["color"], ) # Prints(Height: <>, Period: <>, etc.) - print_ocean_data(arguments) + print_ocean_data(arguments, data_dict) print("\n") forecast = api.forecast( data_dict["Lat"], From de8b9aaedb07313eac0242b3320a3d6bf83f8920 Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Sat, 8 Jun 2024 15:19:35 -0700 Subject: [PATCH 02/17] cheat sheet grammar --- docs/cheat_sheet.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cheat_sheet.md b/docs/cheat_sheet.md index 7b343a7..57022f3 100644 --- a/docs/cheat_sheet.md +++ b/docs/cheat_sheet.md @@ -6,7 +6,7 @@ When developing, these commands may come in handy: | Argument | Description| | -------- | ------- | -| `sudo ss -lptn 'sport = :` | List the processes running on port ``. | +| `sudo ss -lptn 'sport = :'` | List the processes running on port ``. | | `sudo kill -9 ` | Kill the process with with id `` | ## [Poetry Commands](https://python-poetry.org/docs/basic-usage/) From c70a771de7e5ff05bc2818ef80fcbcac0647d88a Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Sat, 8 Jun 2024 15:22:32 -0700 Subject: [PATCH 03/17] new args added to readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c318e0e..f116338 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,9 @@ Wave Period: 9.8 | forecast / fc | Number of forecast days. Max = 7, default = 0 | | hide_wave / hw | Hide the default wave art | | show_large_wave / slw | Show the large wave art | +| show_air_temp / sat | Show the air temp | +| show_wind_speed / sws | Show the wind speed | +| show_wind_direction / swd | Show the wind direction | | hide_uv / huv | Hide uv index | | hide_height / hh | Hide surf height | | hide_direction / hdir | Hide Swell direction | From b9a81cdccd1dcf15777d833da73b639aa096eb97 Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Sat, 8 Jun 2024 15:31:57 -0700 Subject: [PATCH 04/17] new cheat sheet command --- docs/cheat_sheet.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cheat_sheet.md b/docs/cheat_sheet.md index 57022f3..aa3f72e 100644 --- a/docs/cheat_sheet.md +++ b/docs/cheat_sheet.md @@ -8,6 +8,7 @@ When developing, these commands may come in handy: | -------- | ------- | | `sudo ss -lptn 'sport = :'` | List the processes running on port ``. | | `sudo kill -9 ` | Kill the process with with id `` | +| `pre-commit run --all-files` | Run the Linter & Formatter | ## [Poetry Commands](https://python-poetry.org/docs/basic-usage/) From 0346daa8f3aec8ba63e780a04efc52c800a92ab5 Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Sat, 8 Jun 2024 15:33:15 -0700 Subject: [PATCH 05/17] ignore linter branch warning --- src/api.py | 21 ++++++++------------- src/helper.py | 3 ++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/api.py b/src/api.py index 2d06e45..5eae1d2 100644 --- a/src/api.py +++ b/src/api.py @@ -117,17 +117,16 @@ def ocean_information(lat, long, decimal, unit="imperial"): return [current_wave_height, current_wave_direction, current_wave_period] + def current_wind_temp(lat, long, decimal, temp_unit="fahrenheit"): """ Gathers the wind and temperature data """ # Setup the Open-Meteo API client with cache and retry on error - cache_session = requests_cache.CachedSession('.cache', expire_after = 3600) - retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2) - openmeteo = openmeteo_requests.Client(session = retry_session) + cache_session = requests_cache.CachedSession(".cache", expire_after=3600) + retry_session = retry(cache_session, retries=5, backoff_factor=0.2) + openmeteo = openmeteo_requests.Client(session=retry_session) - # Make sure all required weather variables are listed here - # The order of variables in hourly or daily is important to assign them correctly below url = "https://api.open-meteo.com/v1/forecast" params = { "latitude": lat, @@ -135,21 +134,17 @@ def current_wind_temp(lat, long, decimal, temp_unit="fahrenheit"): "current": ["temperature_2m", "wind_speed_10m", "wind_direction_10m"], "temperature_unit": temp_unit, "wind_speed_unit": "mph", - "precipitation_unit": "inch" + "precipitation_unit": "inch", } responses = openmeteo.weather_api(url, params=params) - # Process first location. Add a for-loop for multiple locations or weather models response = responses[0] # Current values. The order of variables needs to be the same as requested. current = response.Current() - current_temperature = round( - current.Variables(0).Value(), decimal) - current_wind_speed = round( - current.Variables(1).Value(), decimal) - current_wind_direction = round( - current.Variables(2).Value(), decimal) + current_temperature = round(current.Variables(0).Value(), decimal) + current_wind_speed = round(current.Variables(1).Value(), decimal) + current_wind_direction = round(current.Variables(2).Value(), decimal) return current_temperature, current_wind_speed, current_wind_direction diff --git a/src/helper.py b/src/helper.py index 027a6dd..01d1f77 100644 --- a/src/helper.py +++ b/src/helper.py @@ -42,7 +42,7 @@ def arguments_dictionary(lat, long, city, args): return arguments -def set_output_values(args, arguments): +def set_output_values(args, arguments): # noqa """ Takes a list of command line arguments(args) and sets the appropritate values @@ -77,6 +77,7 @@ def set_output_values(args, arguments): arguments["show_wind_speed"] = 1 if "show_wind_direction" in args or "swd" in args: arguments["show_wind_direction"] = 1 + return arguments From 70f36924f7d27d9641940c85d8fa0d4f27c07368 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:36:49 +0000 Subject: [PATCH 06/17] Bump urllib3 from 2.2.1 to 2.2.2 in the pip group across 1 directory Bumps the pip group with 1 update in the / directory: [urllib3](https://github.com/urllib3/urllib3). Updates `urllib3` from 2.2.1 to 2.2.2 - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/2.2.1...2.2.2) --- updated-dependencies: - dependency-name: urllib3 dependency-type: indirect dependency-group: pip ... Signed-off-by: dependabot[bot] --- poetry.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index 05eedc7..2250fd6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aiohttp" @@ -1844,13 +1844,13 @@ six = "*" [[package]] name = "urllib3" -version = "2.2.1" +version = "2.2.2" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false python-versions = ">=3.8" files = [ - {file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"}, - {file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"}, + {file = "urllib3-2.2.2-py3-none-any.whl", hash = "sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472"}, + {file = "urllib3-2.2.2.tar.gz", hash = "sha256:dd505485549a7a552833da5e6063639d0d177c04f23bc3864e41e5dc5f612168"}, ] [package.extras] From 58127538acde059d989ef7b68d849fc9f15f4523 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 19:31:27 +0000 Subject: [PATCH 07/17] Bump the pip group across 1 directory with 2 updates Bumps the pip group with 2 updates in the / directory: [certifi](https://github.com/certifi/python-certifi) and [zipp](https://github.com/jaraco/zipp). Updates `certifi` from 2024.2.2 to 2024.7.4 - [Commits](https://github.com/certifi/python-certifi/compare/2024.02.02...2024.07.04) Updates `zipp` from 3.19.0 to 3.19.1 - [Release notes](https://github.com/jaraco/zipp/releases) - [Changelog](https://github.com/jaraco/zipp/blob/main/NEWS.rst) - [Commits](https://github.com/jaraco/zipp/compare/v3.19.0...v3.19.1) --- updated-dependencies: - dependency-name: certifi dependency-type: indirect dependency-group: pip - dependency-name: zipp dependency-type: indirect dependency-group: pip ... Signed-off-by: dependabot[bot] --- poetry.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/poetry.lock b/poetry.lock index 2250fd6..b22fcaa 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohttp" @@ -303,13 +303,13 @@ ujson = ["ujson (>=5.7.0)"] [[package]] name = "certifi" -version = "2024.2.2" +version = "2024.7.4" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2024.2.2-py3-none-any.whl", hash = "sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1"}, - {file = "certifi-2024.2.2.tar.gz", hash = "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f"}, + {file = "certifi-2024.7.4-py3-none-any.whl", hash = "sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90"}, + {file = "certifi-2024.7.4.tar.gz", hash = "sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b"}, ] [[package]] @@ -2001,18 +2001,18 @@ multidict = ">=4.0" [[package]] name = "zipp" -version = "3.19.0" +version = "3.19.1" description = "Backport of pathlib-compatible object wrapper for zip files" optional = false python-versions = ">=3.8" files = [ - {file = "zipp-3.19.0-py3-none-any.whl", hash = "sha256:96dc6ad62f1441bcaccef23b274ec471518daf4fbbc580341204936a5a3dddec"}, - {file = "zipp-3.19.0.tar.gz", hash = "sha256:952df858fb3164426c976d9338d3961e8e8b3758e2e059e0f754b8c4262625ee"}, + {file = "zipp-3.19.1-py3-none-any.whl", hash = "sha256:2828e64edb5386ea6a52e7ba7cdb17bb30a73a858f5eb6eb93d8d36f5ea26091"}, + {file = "zipp-3.19.1.tar.gz", hash = "sha256:35427f6d5594f4acf82d25541438348c26736fa9b3afa2754bcd63cdb99d8e8f"}, ] [package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +test = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] [metadata] lock-version = "2.0" From 9004024f1416541557aa16c79244df51a157c7b2 Mon Sep 17 00:00:00 2001 From: Shaiful Azhar Date: Fri, 19 Jul 2024 01:07:16 +0800 Subject: [PATCH 08/17] feat : add frontend loader --- src/static/script.js | 17 +++++++++++++++++ src/templates/index.html | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/static/script.js b/src/static/script.js index 6331647..d21b84b 100644 --- a/src/static/script.js +++ b/src/static/script.js @@ -3,6 +3,9 @@ cancelbutton.addEventListener("click",function(){ document.getElementById("curlInput").value =""; }); +const elLoadingDiv = document.getElementById("loadingDiv"); +elLoadingDiv.style.display = "none"; + document.getElementById("reportForm").addEventListener("submit", function(event) { event.preventDefault(); // Prevent default form submission @@ -42,6 +45,8 @@ function httpGetAsync(theUrl, callback) { document.addEventListener("submit", function() { // Function to make the HTTP GET request and update the HTML content // Function to make the HTTP GET request and update the HTML content + + handleLoadingChange() function fetchDataAndUpdateHTML() { // Make the HTTP GET request // Get the value of the location input field @@ -67,15 +72,27 @@ document.addEventListener("submit", function() { // Update the content of the serverResponse div with the extracted data document.getElementById('serverResponse').innerHTML = extractedData; + handleLoadingChange() }) .catch(error => { console.error('Error fetching data:', error); + handleLoadingChange() }); } // Call the function to fetch data and update HTML content when the form is submitted fetchDataAndUpdateHTML(); }); +function handleLoadingChange() { + // var elLoadingDiv = document.getElementById("loadingDiv"); + if (elLoadingDiv.style.display === "none") { + elLoadingDiv.style.display = "block"; + serverResponse.style.display = "none" + } else { + elLoadingDiv.style.display = "none"; + serverResponse.style.display = "block" + } +} diff --git a/src/templates/index.html b/src/templates/index.html index 9ca3a32..475ad53 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -74,6 +74,15 @@
+
+
+ +
+ +
+