From 9f23b8ef0012913833432118db2fb1640c8961e5 Mon Sep 17 00:00:00 2001 From: cloneofghosts Date: Sat, 13 Jun 2026 16:09:07 -0400 Subject: [PATCH 1/4] Update README and API to support city/country queries; bump version to 1.3.2 --- README.md | 18 ++++++++++++++++-- pirateweather/api.py | 4 ++-- setup.py | 2 +- tests/test_pirateweather.py | 14 +++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4602a03..c428d90 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,20 @@ To use the wrapper: forecast = pirateweather.load_forecast(api_key, lat, lng) ``` +Starting in version 2.9.6 you can use a city,country pair to query the API with. + + + +```python + import pirateweather + + api_key = "YOUR API KEY" + lat = "New York" + lng = "US" + + forecast = pirateweather.load_forecast(api_key, lat, lng) +``` + The ``load_forecast()`` method has a few optional parameters. Providing your API key, a latitude and longitude are the only required parameters. Use the ``forecast.DataBlockType()`` eg. ``currently()``, ``daily()``, ``hourly()``, ``minutely()`` or ``flags()`` methods to load the data you are after. @@ -64,8 +78,8 @@ This makes an API request and returns a **Forecast** object (see below). Parameters: - **key** - Your API key from https://pirateweather.net/en/latest/. -- **latitude** - The latitude of the location for the forecast -- **longitude** - The longitude of the location for the forecast +- **latitude** - The latitude or city name of the location for the forecast +- **longitude** - The longitude or country code of the location for the forecast - **time** - (optional) A datetime object for the forecast either in the past or future - see How Timezones Work below for the details on how timezones are handled in this library. - **units** - (optional) A string of the preferred units of measurement, "auto" is the default. "us","ca","uk","si" are also available. See the API Docs (https://pirateweather.net/en/latest/API/#units) for exactly what each unit means. - **lang** - (optional) A string of the desired language. See https://pirateweather.net/en/latest/API/#language for supported languages. diff --git a/pirateweather/api.py b/pirateweather/api.py index 7bfd4a2..faabe6a 100644 --- a/pirateweather/api.py +++ b/pirateweather/api.py @@ -24,8 +24,8 @@ def load_forecast( ): """Build the request url and loads some or all of the needed json depending on lazy is True. - inLat: The latitude of the forecast - inLong: The longitude of the forecast + inLat: The latitude or city name of the forecast + inLong: The longitude or country code of the forecast time: A datetime.datetime object representing the desired time of the forecast. If no timezone is present, the API assumes local time at the provided latitude and longitude. diff --git a/setup.py b/setup.py index e3ba0ef..5285372 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ def read(fname): setup( name="python-pirateweather", - version="1.3.1", + version="1.3.2", author="cloneofghosts", description=("A thin Python Wrapper for the Pirate Weather API"), license="BSD 2-clause", diff --git a/tests/test_pirateweather.py b/tests/test_pirateweather.py index 1e47fc0..9d1d5f8 100644 --- a/tests/test_pirateweather.py +++ b/tests/test_pirateweather.py @@ -47,6 +47,14 @@ def test_with_language(self): assert forecast.response.status_code == 200 assert forecast.response.url.find("lang=de") >= 0 + def test_with_city_name(self): + """Test querying the API endpoint with a city name.""" + + forecast = pirateweather.load_forecast( + self.api_key, "London", "GB", time=self.time, + ) + assert forecast.response.status_code == 200 + def test_without_time(self): """Test querying the API endpoint.""" @@ -119,9 +127,9 @@ def test_flags(self): ) flags = forecast.flags() - assert len(flags.sources) == 4 - assert len(flags.sourceTimes) == 3 - assert flags.nearestStation == 0 + assert len(flags.sources) == 5 + assert len(flags.sourceTimes) == 4 + assert flags.nearestStation == 11.97 assert flags.units == "si" assert flags.sourceTimes.get("gfs") assert flags.processTime From 5b81004560ac4cf0ac14f906df2bd4a933f717e6 Mon Sep 17 00:00:00 2001 From: cloneofghosts <10248058+cloneofghosts@users.noreply.github.com> Date: Sat, 13 Jun 2026 20:09:23 +0000 Subject: [PATCH 2/4] style fixes by ruff --- tests/test_pirateweather.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_pirateweather.py b/tests/test_pirateweather.py index 9d1d5f8..b6eea8f 100644 --- a/tests/test_pirateweather.py +++ b/tests/test_pirateweather.py @@ -51,7 +51,10 @@ def test_with_city_name(self): """Test querying the API endpoint with a city name.""" forecast = pirateweather.load_forecast( - self.api_key, "London", "GB", time=self.time, + self.api_key, + "London", + "GB", + time=self.time, ) assert forecast.response.status_code == 200 From c544a9d7f564a4fa642c261fc05291fb4ab6592a Mon Sep 17 00:00:00 2001 From: cloneofghosts Date: Sat, 13 Jun 2026 16:12:22 -0400 Subject: [PATCH 3/4] Update README to clarify city,country example --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c428d90..d5279b4 100644 --- a/README.md +++ b/README.md @@ -36,18 +36,16 @@ To use the wrapper: forecast = pirateweather.load_forecast(api_key, lat, lng) ``` -Starting in version 2.9.6 you can use a city,country pair to query the API with. - - +Starting in version 2.9.6 you can use a city,country pair to query the API with and can be used like this: ```python import pirateweather api_key = "YOUR API KEY" - lat = "New York" - lng = "US" + city_name = "New York" + country_name = "US" - forecast = pirateweather.load_forecast(api_key, lat, lng) + forecast = pirateweather.load_forecast(api_key, city_name, country_name) ``` The ``load_forecast()`` method has a few optional parameters. Providing your API key, a latitude and longitude are the only required parameters. From ebed28b9779a66f5bb8f2847668ee84739f9734f Mon Sep 17 00:00:00 2001 From: Kev Date: Sat, 13 Jun 2026 16:25:03 -0400 Subject: [PATCH 4/4] Update nearest station docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5279b4..d187b0a 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ Contains data about the flags used to generate the forecast. - **version** - The version of Pirate Weather used to generate the forecast. - **nearestStation** - - Not implemented, and will always return 0. + - The distance to the closest MOSMIX station to your location. If no station is nearby the return value will be -999. - **sources** - The models used to generate the forecast. - **sourceTimes**