Skip to content

Commit 5e72f19

Browse files
Update README and API to support city/country queries (#205)
1 parent ae5ed8a commit 5e72f19

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ To use the wrapper:
3636
forecast = pirateweather.load_forecast(api_key, lat, lng)
3737
```
3838

39+
Starting in version 2.9.6 you can use a city,country pair to query the API with and can be used like this:
40+
41+
```python
42+
import pirateweather
43+
44+
api_key = "YOUR API KEY"
45+
city_name = "New York"
46+
country_name = "US"
47+
48+
forecast = pirateweather.load_forecast(api_key, city_name, country_name)
49+
```
50+
3951
The ``load_forecast()`` method has a few optional parameters. Providing your API key, a latitude and longitude are the only required parameters.
4052

4153
Use the ``forecast.DataBlockType()`` eg. ``currently()``, ``daily()``, ``hourly()``, ``minutely()`` or ``flags()`` methods to load the data you are after.
@@ -64,8 +76,8 @@ This makes an API request and returns a **Forecast** object (see below).
6476

6577
Parameters:
6678
- **key** - Your API key from https://pirateweather.net/en/latest/.
67-
- **latitude** - The latitude of the location for the forecast
68-
- **longitude** - The longitude of the location for the forecast
79+
- **latitude** - The latitude or city name of the location for the forecast
80+
- **longitude** - The longitude or country code of the location for the forecast
6981
- **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.
7082
- **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.
7183
- **lang** - (optional) A string of the desired language. See https://pirateweather.net/en/latest/API/#language for supported languages.
@@ -174,7 +186,7 @@ Contains data about the flags used to generate the forecast.
174186
- **version**
175187
- The version of Pirate Weather used to generate the forecast.
176188
- **nearestStation**
177-
- Not implemented, and will always return 0.
189+
- The distance to the closest MOSMIX station to your location. If no station is nearby the return value will be -999.
178190
- **sources**
179191
- The models used to generate the forecast.
180192
- **sourceTimes**

pirateweather/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def load_forecast(
2424
):
2525
"""Build the request url and loads some or all of the needed json depending on lazy is True.
2626
27-
inLat: The latitude of the forecast
28-
inLong: The longitude of the forecast
27+
inLat: The latitude or city name of the forecast
28+
inLong: The longitude or country code of the forecast
2929
time: A datetime.datetime object representing the desired time of
3030
the forecast. If no timezone is present, the API assumes local
3131
time at the provided latitude and longitude.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def read(fname):
2020

2121
setup(
2222
name="python-pirateweather",
23-
version="1.3.1",
23+
version="1.3.2",
2424
author="cloneofghosts",
2525
description=("A thin Python Wrapper for the Pirate Weather API"),
2626
license="BSD 2-clause",

tests/test_pirateweather.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ def test_with_language(self):
4747
assert forecast.response.status_code == 200
4848
assert forecast.response.url.find("lang=de") >= 0
4949

50+
def test_with_city_name(self):
51+
"""Test querying the API endpoint with a city name."""
52+
53+
forecast = pirateweather.load_forecast(
54+
self.api_key,
55+
"London",
56+
"GB",
57+
time=self.time,
58+
)
59+
assert forecast.response.status_code == 200
60+
5061
def test_without_time(self):
5162
"""Test querying the API endpoint."""
5263

@@ -119,9 +130,9 @@ def test_flags(self):
119130
)
120131
flags = forecast.flags()
121132

122-
assert len(flags.sources) == 4
123-
assert len(flags.sourceTimes) == 3
124-
assert flags.nearestStation == 0
133+
assert len(flags.sources) == 5
134+
assert len(flags.sourceTimes) == 4
135+
assert flags.nearestStation == 11.97
125136
assert flags.units == "si"
126137
assert flags.sourceTimes.get("gfs")
127138
assert flags.processTime

0 commit comments

Comments
 (0)