openvan 0.1.0__tar.gz → 0.2.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.1.0 → openvan-0.2.0}/PKG-INFO +5 -1
- {openvan-0.1.0 → openvan-0.2.0}/README.md +4 -0
- {openvan-0.1.0 → openvan-0.2.0}/src/openvan/api.py +19 -3
- {openvan-0.1.0 → openvan-0.2.0}/src/openvan/client.py +1 -1
- {openvan-0.1.0 → openvan-0.2.0}/tests/test_openvan.py +28 -0
- {openvan-0.1.0 → openvan-0.2.0}/.gitignore +0 -0
- {openvan-0.1.0 → openvan-0.2.0}/LICENSE +0 -0
- {openvan-0.1.0 → openvan-0.2.0}/pyproject.toml +0 -0
- {openvan-0.1.0 → openvan-0.2.0}/src/openvan/__init__.py +0 -0
- {openvan-0.1.0 → openvan-0.2.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.2.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,10 @@ 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
|
+
# Typical weather (climate) in Batumi on 18 September and the best month to go
|
|
60
|
+
batumi = ov.weather.city_climate("GE", "batumi", date="09-18")
|
|
61
|
+
print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], batumi["best_month"])
|
|
62
|
+
|
|
59
63
|
# School holidays in Germany this autumn, by federal state
|
|
60
64
|
ov.holidays.country("DE", from_="2026-10-01", to="2026-12-31", kind="school")
|
|
61
65
|
```
|
|
@@ -32,6 +32,10 @@ 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
|
+
# Typical weather (climate) in Batumi on 18 September and the best month to go
|
|
36
|
+
batumi = ov.weather.city_climate("GE", "batumi", date="09-18")
|
|
37
|
+
print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], batumi["best_month"])
|
|
38
|
+
|
|
35
39
|
# School holidays in Germany this autumn, by federal state
|
|
36
40
|
ov.holidays.country("DE", from_="2026-10-01", to="2026-12-31", kind="school")
|
|
37
41
|
```
|
|
@@ -68,8 +68,8 @@ class Fuel(_Resource):
|
|
|
68
68
|
def cheapest(self, fuel_type: str = "diesel", limit: int = 10) -> List[JSON]:
|
|
69
69
|
"""Cheapest countries for a fuel type, in EUR per liter, cheapest first.
|
|
70
70
|
|
|
71
|
-
Each grade is converted with its own currency (``currencies``)
|
|
72
|
-
normalized to liters, and countries whose currency has no rate are left out.
|
|
71
|
+
Each grade is converted with its own currency (``currencies``) and unit (``units``):
|
|
72
|
+
gallon prices are normalized to liters, and countries whose currency has no rate are left out.
|
|
73
73
|
"""
|
|
74
74
|
prices = self.prices()
|
|
75
75
|
try:
|
|
@@ -86,7 +86,8 @@ class Fuel(_Resource):
|
|
|
86
86
|
if not rate:
|
|
87
87
|
return math.nan
|
|
88
88
|
eur = price / rate
|
|
89
|
-
|
|
89
|
+
unit = (country.get("units") or {}).get(fuel_type) or country.get("unit", "")
|
|
90
|
+
return eur / LITERS_PER_GALLON if "gal" in str(unit).lower() else eur
|
|
90
91
|
|
|
91
92
|
ranked = [(eur_per_liter(c), c) for c in prices.values()]
|
|
92
93
|
ranked = [x for x in ranked if not math.isnan(x[0])]
|
|
@@ -150,6 +151,21 @@ class Weather(_Resource):
|
|
|
150
151
|
"""Top countries by vanlife weather suitability today, best first."""
|
|
151
152
|
return sorted(self.all(), key=lambda c: c.get("van_score") or 0, reverse=True)[:limit]
|
|
152
153
|
|
|
154
|
+
def climate(self, lat: float, lng: float, date: Optional[str] = None) -> JSON:
|
|
155
|
+
"""Typical weather (climate) at any point: median of 35 archive days (the date ±3 days over
|
|
156
|
+
2021–2025, ERA5). With ``date`` (``MM-DD`` or ``YYYY-MM-DD``) the result has ``day``; without it,
|
|
157
|
+
``days`` holds all 366 days. ``months``, ``best_month`` and ``good_months`` are always included.
|
|
158
|
+
"""
|
|
159
|
+
return self.client.get("/api/vansky/climate", {"lat": lat, "lng": lng, "date": date})
|
|
160
|
+
|
|
161
|
+
def city_climate(
|
|
162
|
+
self, code: str, city_slug: str, date: Optional[str] = None, locale: Optional[str] = None
|
|
163
|
+
) -> JSON:
|
|
164
|
+
"""The same as :meth:`climate` for a VanSky city, plus the city name and page URL."""
|
|
165
|
+
return self.client.get(
|
|
166
|
+
f"/api/vansky/climate/{code.upper()}/{quote(city_slug)}", {"date": date, "locale": locale}
|
|
167
|
+
)
|
|
168
|
+
|
|
153
169
|
|
|
154
170
|
class Events(_Resource):
|
|
155
171
|
def list(self, **filters: Any) -> JSON:
|
|
@@ -79,6 +79,19 @@ class OpenVanTest(unittest.TestCase):
|
|
|
79
79
|
# XX has no rate and is left out instead of being compared as EUR.
|
|
80
80
|
self.assertEqual([c["country_code"] for c in ranked], ["VE", "US", "DE"])
|
|
81
81
|
|
|
82
|
+
def test_cheapest_uses_the_unit_of_each_grade(self):
|
|
83
|
+
# Colombia: the country record says liters, but diesel is sold per gallon.
|
|
84
|
+
fuel = {"data": {
|
|
85
|
+
"DE": {"country_code": "DE", "currency": "EUR", "unit": "liter", "prices": {"diesel": 1.70}},
|
|
86
|
+
"CO": {"country_code": "CO", "currency": "COP", "unit": "liter",
|
|
87
|
+
"units": {"diesel": "gallon"}, "prices": {"diesel": 11219.5}},
|
|
88
|
+
}}
|
|
89
|
+
fake, _ = respond({"/api/fuel/prices": fuel, "/api/currency/rates": {"rates": {"EUR": 1, "COP": 4400.0}}})
|
|
90
|
+
with mock.patch("openvan.client.urlopen", fake):
|
|
91
|
+
ranked = OpenVan().fuel.cheapest("diesel")
|
|
92
|
+
# 11219.5 COP / 4400 = 2.55 € per gallon = 0.67 €/l, cheaper than DE at 1.70 €/l.
|
|
93
|
+
self.assertEqual([c["country_code"] for c in ranked], ["CO", "DE"])
|
|
94
|
+
|
|
82
95
|
def test_weather_score_calls_country_endpoint(self):
|
|
83
96
|
fake, calls = respond({"/api/vansky/weather/FR": {"data": {"code": "FR", "van_score": 89}}})
|
|
84
97
|
with mock.patch("openvan.client.urlopen", fake):
|
|
@@ -91,6 +104,21 @@ class OpenVanTest(unittest.TestCase):
|
|
|
91
104
|
with mock.patch("openvan.client.urlopen", fake):
|
|
92
105
|
self.assertEqual([c["code"] for c in OpenVan().weather.top(2)], ["B", "C"])
|
|
93
106
|
|
|
107
|
+
def test_climate_point_passes_lat_lng_and_date(self):
|
|
108
|
+
fake, calls = respond({"/api/vansky/climate": {"period": "2021–2025", "day": {"date": "09-18"}}})
|
|
109
|
+
with mock.patch("openvan.client.urlopen", fake):
|
|
110
|
+
self.assertEqual(OpenVan().weather.climate(41.64, 41.63, "09-18")["day"]["date"], "09-18")
|
|
111
|
+
q = parse_qs(urlparse(calls[0].full_url).query)
|
|
112
|
+
self.assertEqual((q["lat"], q["lng"], q["date"]), (["41.64"], ["41.63"], ["09-18"]))
|
|
113
|
+
|
|
114
|
+
def test_city_climate_without_date_drops_empty_params(self):
|
|
115
|
+
fake, calls = respond({"/api/vansky/climate/GE/batumi": {"period": "2021–2025", "months": []}})
|
|
116
|
+
with mock.patch("openvan.client.urlopen", fake):
|
|
117
|
+
OpenVan().weather.city_climate("ge", "batumi")
|
|
118
|
+
url = urlparse(calls[0].full_url)
|
|
119
|
+
self.assertEqual(url.path, "/api/vansky/climate/GE/batumi")
|
|
120
|
+
self.assertNotIn("date", parse_qs(url.query))
|
|
121
|
+
|
|
94
122
|
def test_route_cost_posts_json(self):
|
|
95
123
|
fake, calls = respond({"/api/route-cost": {"distance_km": 345}})
|
|
96
124
|
with mock.patch("openvan.client.urlopen", fake):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|