python-pirateweather 1.0.0__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_pirateweather-1.0.0/python_pirateweather.egg-info → python_pirateweather-1.0.2}/PKG-INFO +1 -1
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/pirateweather/api.py +15 -3
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/pirateweather/models.py +8 -20
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/pirateweather/utils.py +0 -4
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2/python_pirateweather.egg-info}/PKG-INFO +1 -1
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/setup.py +1 -1
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/tests/test_pirateweather.py +38 -9
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/LICENSE.txt +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/MANIFEST.in +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/README.md +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/pirateweather/__init__.py +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/python_pirateweather.egg-info/SOURCES.txt +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/python_pirateweather.egg-info/dependency_links.txt +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/python_pirateweather.egg-info/requires.txt +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/python_pirateweather.egg-info/top_level.txt +0 -0
- {python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/setup.cfg +0 -0
|
@@ -8,7 +8,16 @@ from pirateweather.models import Forecast
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def load_forecast(
|
|
11
|
-
key,
|
|
11
|
+
key,
|
|
12
|
+
lat,
|
|
13
|
+
lng,
|
|
14
|
+
time=None,
|
|
15
|
+
units="us",
|
|
16
|
+
lang="en",
|
|
17
|
+
lazy=False,
|
|
18
|
+
callback=None,
|
|
19
|
+
extend=None,
|
|
20
|
+
version=1,
|
|
12
21
|
):
|
|
13
22
|
"""Build the request url and loads some or all of the needed json depending on lazy is True.
|
|
14
23
|
|
|
@@ -17,18 +26,21 @@ def load_forecast(
|
|
|
17
26
|
time: A datetime.datetime object representing the desired time of
|
|
18
27
|
the forecast. If no timezone is present, the API assumes local
|
|
19
28
|
time at the provided latitude and longitude.
|
|
20
|
-
units: A string of the preferred units of measurement, "us"
|
|
29
|
+
units: A string of the preferred units of measurement, "us" is
|
|
21
30
|
default. also ca,uk,si is available
|
|
22
31
|
lang: Return summary properties in the desired language
|
|
23
32
|
lazy: Defaults to false. The function will only request the json
|
|
24
33
|
data as it is needed. Results in more requests, but
|
|
25
34
|
probably a faster response time (I haven't checked)
|
|
35
|
+
extend: If set to true the API will hourly data for 168 hours instead
|
|
36
|
+
of the standard 48 hours.
|
|
37
|
+
version: If set to 2 the API will return fields that were not part of the Dark Sky API.
|
|
26
38
|
"""
|
|
27
39
|
|
|
28
40
|
if time is None:
|
|
29
41
|
url = (
|
|
30
42
|
f"https://api.pirateweather.net/forecast/{key}/{lat},{lng}"
|
|
31
|
-
f"?units={units}&lang={lang}"
|
|
43
|
+
f"?units={units}&lang={lang}&extend={extend}&version={version}"
|
|
32
44
|
)
|
|
33
45
|
else:
|
|
34
46
|
url_time = time.replace(
|
|
@@ -4,7 +4,7 @@ import datetime
|
|
|
4
4
|
|
|
5
5
|
import requests
|
|
6
6
|
|
|
7
|
-
from pirateweather.utils import
|
|
7
|
+
from pirateweather.utils import UnicodeMixin
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class Forecast(UnicodeMixin):
|
|
@@ -88,14 +88,7 @@ class PirateWeatherDataBlock(UnicodeMixin):
|
|
|
88
88
|
|
|
89
89
|
def __unicode__(self):
|
|
90
90
|
"""Return a string representation of the data block."""
|
|
91
|
-
return (
|
|
92
|
-
"<PirateWeatherDataBlock instance: "
|
|
93
|
-
"%s with %d PirateWeatherDataPoints>"
|
|
94
|
-
% (
|
|
95
|
-
self.summary,
|
|
96
|
-
len(self.data),
|
|
97
|
-
)
|
|
98
|
-
)
|
|
91
|
+
return f"<PirateWeatherDataBlock instance: {self.summary} with {len(self.data)} PirateWeatherDataPoints>"
|
|
99
92
|
|
|
100
93
|
|
|
101
94
|
class PirateWeatherDataPoint(UnicodeMixin):
|
|
@@ -124,14 +117,11 @@ class PirateWeatherDataPoint(UnicodeMixin):
|
|
|
124
117
|
self.sunsetTime = None
|
|
125
118
|
|
|
126
119
|
def __getattr__(self, name):
|
|
127
|
-
"""Return the weather property dynamically or
|
|
120
|
+
"""Return the weather property dynamically or return None if missing."""
|
|
128
121
|
try:
|
|
129
122
|
return self.d[name]
|
|
130
|
-
except KeyError
|
|
131
|
-
|
|
132
|
-
f"Property '{name}' is not valid"
|
|
133
|
-
" or is not available for this forecast"
|
|
134
|
-
) from err
|
|
123
|
+
except KeyError:
|
|
124
|
+
return None
|
|
135
125
|
|
|
136
126
|
def __unicode__(self):
|
|
137
127
|
"""Return a string representation of the data point."""
|
|
@@ -146,13 +136,11 @@ class Alert(UnicodeMixin):
|
|
|
146
136
|
self.json = json
|
|
147
137
|
|
|
148
138
|
def __getattr__(self, name):
|
|
149
|
-
"""Return the alert property dynamically or
|
|
139
|
+
"""Return the alert property dynamically or return None if missing."""
|
|
150
140
|
try:
|
|
151
141
|
return self.json[name]
|
|
152
|
-
except KeyError
|
|
153
|
-
|
|
154
|
-
f"Property '{name}' is not valid" " or is not available for this alert"
|
|
155
|
-
) from err
|
|
142
|
+
except KeyError:
|
|
143
|
+
return None
|
|
156
144
|
|
|
157
145
|
def __unicode__(self):
|
|
158
146
|
"""Return a string representation of the alert."""
|
|
@@ -7,7 +7,3 @@ class UnicodeMixin:
|
|
|
7
7
|
def __str__(self):
|
|
8
8
|
"""Return the unicode representation of the object for Python 3 compatibility."""
|
|
9
9
|
return self.__unicode__()
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class PropertyUnavailable(AttributeError):
|
|
13
|
-
"""Raise when a requested property is unavailable in the forecast data."""
|
|
@@ -7,7 +7,6 @@ from datetime import datetime
|
|
|
7
7
|
import pytest
|
|
8
8
|
import requests
|
|
9
9
|
import responses
|
|
10
|
-
from nose.tools import raises
|
|
11
10
|
|
|
12
11
|
import pirateweather
|
|
13
12
|
|
|
@@ -19,11 +18,11 @@ class EndToEnd(unittest.TestCase):
|
|
|
19
18
|
"""Set up the API key, location and time for the tests."""
|
|
20
19
|
|
|
21
20
|
self.api_key = os.environ.get("PIRATEWEATHER_API_KEY")
|
|
22
|
-
|
|
23
21
|
self.lat = 52.370235
|
|
24
22
|
self.lng = 4.903549
|
|
25
|
-
|
|
26
23
|
self.time = datetime(2015, 2, 27, 6, 0, 0)
|
|
24
|
+
self.extend = "hourly"
|
|
25
|
+
self.version = 2
|
|
27
26
|
|
|
28
27
|
def test_with_time(self):
|
|
29
28
|
"""Test querying the TimeMachine API endpoint."""
|
|
@@ -50,6 +49,38 @@ class EndToEnd(unittest.TestCase):
|
|
|
50
49
|
forecast = pirateweather.load_forecast(self.api_key, self.lat, self.lng)
|
|
51
50
|
assert forecast.response.status_code == 200
|
|
52
51
|
|
|
52
|
+
def test_extend(self):
|
|
53
|
+
"""Test querying the API endpoint."""
|
|
54
|
+
|
|
55
|
+
forecast = pirateweather.load_forecast(
|
|
56
|
+
self.api_key, self.lat, self.lng, None, "us", "en", False, None, self.extend
|
|
57
|
+
)
|
|
58
|
+
hourl_data = forecast.hourly()
|
|
59
|
+
|
|
60
|
+
assert forecast.response.status_code == 200
|
|
61
|
+
assert len(hourl_data.data) == 169
|
|
62
|
+
|
|
63
|
+
def test_version(self):
|
|
64
|
+
"""Test querying the API endpoint."""
|
|
65
|
+
|
|
66
|
+
forecast = pirateweather.load_forecast(
|
|
67
|
+
self.api_key, self.lat, self.lng, None, "us", "en", False, None, None, 2
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
assert forecast.response.status_code == 200
|
|
71
|
+
assert forecast.response.url.find("version=2") >= 0
|
|
72
|
+
|
|
73
|
+
def test_version_data_point(self):
|
|
74
|
+
"""Test querying the API endpoint."""
|
|
75
|
+
|
|
76
|
+
forecast = pirateweather.load_forecast(
|
|
77
|
+
self.api_key, self.lat, self.lng, None, "us", "en", False, None, None, 2
|
|
78
|
+
)
|
|
79
|
+
fc_cur = forecast.currently()
|
|
80
|
+
|
|
81
|
+
assert forecast.response.status_code == 200
|
|
82
|
+
assert fc_cur.fireIndex
|
|
83
|
+
|
|
53
84
|
def test_invalid_key(self):
|
|
54
85
|
"""Test querying the API endpoint with a invalid API key."""
|
|
55
86
|
|
|
@@ -86,7 +117,7 @@ class BasicFunctionality(unittest.TestCase):
|
|
|
86
117
|
def setUp(self):
|
|
87
118
|
"""Set up the data to use in the next tests."""
|
|
88
119
|
|
|
89
|
-
URL = "https://api.pirateweather.net/forecast/foo/50.0,10.0?units=us&lang=en"
|
|
120
|
+
URL = "https://api.pirateweather.net/forecast/foo/50.0,10.0?units=us&lang=en&extend=None&version=1"
|
|
90
121
|
responses.add(
|
|
91
122
|
responses.GET,
|
|
92
123
|
URL,
|
|
@@ -159,12 +190,11 @@ class BasicFunctionality(unittest.TestCase):
|
|
|
159
190
|
== "<PirateWeatherDataBlock instance: Drizzle until this evening. with 49 PirateWeatherDataPoints>"
|
|
160
191
|
)
|
|
161
192
|
|
|
162
|
-
@raises(pirateweather.utils.PropertyUnavailable)
|
|
163
193
|
def test_datapoint_attribute_not_available(self):
|
|
164
194
|
"""Test fetching an invalid property on the daily block."""
|
|
165
195
|
|
|
166
196
|
daily = self.fc.daily()
|
|
167
|
-
daily.data[0].notavailable
|
|
197
|
+
assert daily.data[0].notavailable is None
|
|
168
198
|
|
|
169
199
|
def test_apparentTemperature(self):
|
|
170
200
|
"""Test the first hour data block apparent temperature."""
|
|
@@ -188,7 +218,7 @@ class ForecastsWithAlerts(unittest.TestCase):
|
|
|
188
218
|
def setUp(self):
|
|
189
219
|
"""Set up the test data with alerts to use in the next tests."""
|
|
190
220
|
|
|
191
|
-
URL = "https://api.pirateweather.net/forecast/foo/50.0,10.0?units=us&lang=en"
|
|
221
|
+
URL = "https://api.pirateweather.net/forecast/foo/50.0,10.0?units=us&lang=en&extend=None&version=1"
|
|
192
222
|
responses.add(
|
|
193
223
|
responses.GET,
|
|
194
224
|
URL,
|
|
@@ -236,14 +266,13 @@ class ForecastsWithAlerts(unittest.TestCase):
|
|
|
236
266
|
|
|
237
267
|
assert first_alert.time == 1402133400
|
|
238
268
|
|
|
239
|
-
@raises(pirateweather.utils.PropertyUnavailable)
|
|
240
269
|
def test_alert_property_does_not_exist(self):
|
|
241
270
|
"""Test fetching an invalid property on the alerts."""
|
|
242
271
|
|
|
243
272
|
alerts = self.fc.alerts()
|
|
244
273
|
first_alert = alerts[0]
|
|
245
274
|
|
|
246
|
-
first_alert.notarealproperty
|
|
275
|
+
assert first_alert.notarealproperty is None
|
|
247
276
|
|
|
248
277
|
def test_alert_string_repr(self):
|
|
249
278
|
"""Test the string representation of the currently data."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/python_pirateweather.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{python_pirateweather-1.0.0 → python_pirateweather-1.0.2}/python_pirateweather.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|