openvan 0.2.0__tar.gz → 0.3.0__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.
- {openvan-0.2.0 → openvan-0.3.0}/PKG-INFO +6 -1
- {openvan-0.2.0 → openvan-0.3.0}/README.md +5 -0
- {openvan-0.2.0 → openvan-0.3.0}/src/openvan/api.py +27 -0
- {openvan-0.2.0 → openvan-0.3.0}/src/openvan/client.py +1 -1
- {openvan-0.2.0 → openvan-0.3.0}/tests/test_openvan.py +12 -0
- {openvan-0.2.0 → openvan-0.3.0}/.gitignore +0 -0
- {openvan-0.2.0 → openvan-0.3.0}/LICENSE +0 -0
- {openvan-0.2.0 → openvan-0.3.0}/pyproject.toml +0 -0
- {openvan-0.2.0 → openvan-0.3.0}/src/openvan/__init__.py +0 -0
- {openvan-0.2.0 → openvan-0.3.0}/src/openvan/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: openvan
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Free vanlife & RV travel data: fuel prices in 160+ countries, toll roads, visa rules, holidays, travel hazards, weather scores, currency. No API key.
|
|
5
5
|
Project-URL: Homepage, https://openvan.camp/en/developers?utm_source=pypi&utm_medium=referral&utm_campaign=python-sdk
|
|
6
6
|
Project-URL: Documentation, https://openvan.camp/docs?utm_source=pypi&utm_medium=referral&utm_campaign=python-sdk
|
|
@@ -56,6 +56,11 @@ print(ov.tolls.route(["Rome", "Paris"], vehicle_class="van"))
|
|
|
56
56
|
for c in ov.weather.top(5):
|
|
57
57
|
print(c["code"], c["van_score"], c["score_label"])
|
|
58
58
|
|
|
59
|
+
# Countries of Europe by the score of the coming week (the site ranking), one city with its place
|
|
60
|
+
for c in ov.weather.ranking(region="europe", limit=5):
|
|
61
|
+
print(c["rank"], c["name"], c["week_score"])
|
|
62
|
+
print(ov.weather.city("GE", "batumi")["rank"])
|
|
63
|
+
|
|
59
64
|
# Typical weather (climate) in Batumi on 18 September and the best month to go
|
|
60
65
|
batumi = ov.weather.city_climate("GE", "batumi", date="09-18")
|
|
61
66
|
print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], batumi["best_month"])
|
|
@@ -32,6 +32,11 @@ print(ov.tolls.route(["Rome", "Paris"], vehicle_class="van"))
|
|
|
32
32
|
for c in ov.weather.top(5):
|
|
33
33
|
print(c["code"], c["van_score"], c["score_label"])
|
|
34
34
|
|
|
35
|
+
# Countries of Europe by the score of the coming week (the site ranking), one city with its place
|
|
36
|
+
for c in ov.weather.ranking(region="europe", limit=5):
|
|
37
|
+
print(c["rank"], c["name"], c["week_score"])
|
|
38
|
+
print(ov.weather.city("GE", "batumi")["rank"])
|
|
39
|
+
|
|
35
40
|
# Typical weather (climate) in Batumi on 18 September and the best month to go
|
|
36
41
|
batumi = ov.weather.city_climate("GE", "batumi", date="09-18")
|
|
37
42
|
print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], batumi["best_month"])
|
|
@@ -143,6 +143,33 @@ class Weather(_Resource):
|
|
|
143
143
|
"""Vanlife weather of one country: ``van_score`` 0–100, ``score_label``, 7-day ``forecast``."""
|
|
144
144
|
return self.client.get(f"/api/vansky/weather/{code.upper()}")["data"]
|
|
145
145
|
|
|
146
|
+
def city(self, code: str, city_slug: str, locale: Optional[str] = None, hourly: bool = False) -> JSON:
|
|
147
|
+
"""One city, as on its page: score today and for the coming 7 days, place among the cities of the
|
|
148
|
+
country (``rank``), per-day score breakdown, worst day, best stretch, air quality, recommendations.
|
|
149
|
+
``hourly=True`` adds 3-hour steps.
|
|
150
|
+
"""
|
|
151
|
+
params = {"locale": locale, "include": "hourly" if hourly else None}
|
|
152
|
+
return self.client.get(f"/api/vansky/weather/{code.upper()}/{quote(city_slug)}", params)["data"]
|
|
153
|
+
|
|
154
|
+
def cities(
|
|
155
|
+
self, code: str, sort: str = "week", limit: Optional[int] = None, offset: Optional[int] = None,
|
|
156
|
+
locale: Optional[str] = None,
|
|
157
|
+
) -> JSON:
|
|
158
|
+
"""Cities of a country ranked by the score of the coming 7 days (``sort="week"``, as on the site) or today."""
|
|
159
|
+
params = {"sort": sort, "limit": limit, "offset": offset, "locale": locale}
|
|
160
|
+
return self.client.get(f"/api/vansky/weather/{code.upper()}/cities", params)
|
|
161
|
+
|
|
162
|
+
def ranking(
|
|
163
|
+
self, by: str = "week", region: Optional[str] = None, limit: Optional[int] = None, locale: Optional[str] = None
|
|
164
|
+
) -> List[JSON]:
|
|
165
|
+
"""Countries ranked by the score of the coming 7 days (``by="week"``) or today, optionally in one region."""
|
|
166
|
+
params = {"by": by, "region": region, "limit": limit, "locale": locale}
|
|
167
|
+
return self.client.get("/api/vansky/ranking", params)["data"]
|
|
168
|
+
|
|
169
|
+
def methodology(self) -> JSON:
|
|
170
|
+
"""How the VanSky score is calculated: curves, weights, adjustments, week score."""
|
|
171
|
+
return self.client.get("/api/vansky/methodology")
|
|
172
|
+
|
|
146
173
|
def all(self) -> List[JSON]:
|
|
147
174
|
"""Every country with weather data (one request, ~1 MB)."""
|
|
148
175
|
return self.client.get("/api/vansky/weather")["data"]
|
|
@@ -104,6 +104,18 @@ class OpenVanTest(unittest.TestCase):
|
|
|
104
104
|
with mock.patch("openvan.client.urlopen", fake):
|
|
105
105
|
self.assertEqual([c["code"] for c in OpenVan().weather.top(2)], ["B", "C"])
|
|
106
106
|
|
|
107
|
+
def test_weather_city_hourly_and_ranking(self):
|
|
108
|
+
fake, calls = respond({
|
|
109
|
+
"/api/vansky/weather/GE/batumi": {"data": {"rank": {"position": 10, "total": 32}}},
|
|
110
|
+
"/api/vansky/ranking": {"data": [{"rank": 1, "code": "CL"}]},
|
|
111
|
+
})
|
|
112
|
+
with mock.patch("openvan.client.urlopen", fake):
|
|
113
|
+
self.assertEqual(OpenVan().weather.city("ge", "batumi", hourly=True)["rank"]["position"], 10)
|
|
114
|
+
self.assertEqual(OpenVan().weather.ranking(region="europe", limit=5)[0]["code"], "CL")
|
|
115
|
+
self.assertEqual(parse_qs(urlparse(calls[0].full_url).query)["include"], ["hourly"])
|
|
116
|
+
q = parse_qs(urlparse(calls[1].full_url).query)
|
|
117
|
+
self.assertEqual((q["by"], q["region"], q["limit"]), (["week"], ["europe"], ["5"]))
|
|
118
|
+
|
|
107
119
|
def test_climate_point_passes_lat_lng_and_date(self):
|
|
108
120
|
fake, calls = respond({"/api/vansky/climate": {"period": "2021–2025", "day": {"date": "09-18"}}})
|
|
109
121
|
with mock.patch("openvan.client.urlopen", fake):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|