Skip to content

Commit 9f23b8e

Browse files
committed
Update README and API to support city/country queries; bump version to 1.3.2
1 parent ae5ed8a commit 9f23b8e

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ 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.
40+
41+
42+
43+
```python
44+
import pirateweather
45+
46+
api_key = "YOUR API KEY"
47+
lat = "New York"
48+
lng = "US"
49+
50+
forecast = pirateweather.load_forecast(api_key, lat, lng)
51+
```
52+
3953
The ``load_forecast()`` method has a few optional parameters. Providing your API key, a latitude and longitude are the only required parameters.
4054

4155
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).
6478

6579
Parameters:
6680
- **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
81+
- **latitude** - The latitude or city name of the location for the forecast
82+
- **longitude** - The longitude or country code of the location for the forecast
6983
- **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.
7084
- **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.
7185
- **lang** - (optional) A string of the desired language. See https://pirateweather.net/en/latest/API/#language for supported languages.

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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ 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, "London", "GB", time=self.time,
55+
)
56+
assert forecast.response.status_code == 200
57+
5058
def test_without_time(self):
5159
"""Test querying the API endpoint."""
5260

@@ -119,9 +127,9 @@ def test_flags(self):
119127
)
120128
flags = forecast.flags()
121129

122-
assert len(flags.sources) == 4
123-
assert len(flags.sourceTimes) == 3
124-
assert flags.nearestStation == 0
130+
assert len(flags.sources) == 5
131+
assert len(flags.sourceTimes) == 4
132+
assert flags.nearestStation == 11.97
125133
assert flags.units == "si"
126134
assert flags.sourceTimes.get("gfs")
127135
assert flags.processTime

0 commit comments

Comments
 (0)