simple-dwd-weatherforecast 2.0.25__py3-none-any.whl → 2.0.27__py3-none-any.whl
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.
- simple_dwd_weatherforecast/dwdforecast.py +24 -9
- simple_dwd_weatherforecast/dwdmap.py +7 -6
- simple_dwd_weatherforecast/uv_stations.json +1 -0
- {simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/METADATA +11 -7
- {simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/RECORD +9 -8
- tests/test_weather.py +1 -1
- {simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/LICENCE +0 -0
- {simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/WHEEL +0 -0
- {simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/top_level.txt +0 -0
@@ -16,6 +16,11 @@ with importlib.resources.files("simple_dwd_weatherforecast").joinpath(
|
|
16
16
|
).open("r", encoding="utf-8") as file:
|
17
17
|
stations = json.load(file)
|
18
18
|
|
19
|
+
with importlib.resources.files("simple_dwd_weatherforecast").joinpath(
|
20
|
+
"uv_stations.json"
|
21
|
+
).open("r", encoding="utf-8") as file:
|
22
|
+
uv_stations = json.load(file)
|
23
|
+
|
19
24
|
|
20
25
|
def load_station_id(station_id: str):
|
21
26
|
if station_id in stations:
|
@@ -200,7 +205,7 @@ class Weather:
|
|
200
205
|
"MV": "dwph", # Mecklenburg-Vorpommern
|
201
206
|
}
|
202
207
|
|
203
|
-
|
208
|
+
uv_index_stations_reference_names = {
|
204
209
|
"Weinbiet": "Weinbiet",
|
205
210
|
"Hamburg": "Hamburg Innenstadt",
|
206
211
|
"Seehausen": "Seehausen",
|
@@ -247,7 +252,6 @@ class Weather:
|
|
247
252
|
if self.station:
|
248
253
|
self.station_id = station_id
|
249
254
|
self.region = get_region(station_id)
|
250
|
-
self.download_uv_index()
|
251
255
|
self.nearest_uv_index_station = self.get_nearest_station_id_with_uv()
|
252
256
|
else:
|
253
257
|
raise ValueError("Not a valid station_id")
|
@@ -255,7 +259,7 @@ class Weather:
|
|
255
259
|
def get_nearest_station_id_with_uv(self):
|
256
260
|
nearest_distance = float("inf")
|
257
261
|
nearest_station_id = None
|
258
|
-
for station in
|
262
|
+
for station in uv_stations.items():
|
259
263
|
distance = get_distance(
|
260
264
|
self.station["lat"],
|
261
265
|
self.station["lon"],
|
@@ -265,9 +269,7 @@ class Weather:
|
|
265
269
|
|
266
270
|
if distance < nearest_distance:
|
267
271
|
nearest_distance = distance
|
268
|
-
nearest_station_id =
|
269
|
-
self.uv_index_stations[station[1]["city"]]
|
270
|
-
)
|
272
|
+
nearest_station_id = station[0]
|
271
273
|
|
272
274
|
return nearest_station_id
|
273
275
|
|
@@ -399,6 +401,14 @@ class Weather:
|
|
399
401
|
print("no report for this station available. Have you updated first?")
|
400
402
|
|
401
403
|
def get_uv_index(self, days_from_today: int) -> int:
|
404
|
+
if not self.uv_reports:
|
405
|
+
self.update(
|
406
|
+
force_hourly=False,
|
407
|
+
with_forecast=False,
|
408
|
+
with_measurements=False,
|
409
|
+
with_report=False,
|
410
|
+
with_uv=True,
|
411
|
+
)
|
402
412
|
if days_from_today < 0 or days_from_today > 2:
|
403
413
|
print("days_from_today must be between 0 and 2")
|
404
414
|
return None
|
@@ -408,7 +418,7 @@ class Weather:
|
|
408
418
|
day = "tomorrow"
|
409
419
|
elif days_from_today == 2:
|
410
420
|
day = "dayafter_to"
|
411
|
-
return self.uv_reports[self.nearest_uv_index_station
|
421
|
+
return self.uv_reports[self.nearest_uv_index_station]["forecast"][day]
|
412
422
|
|
413
423
|
def get_timeframe_max(
|
414
424
|
self,
|
@@ -607,6 +617,7 @@ class Weather:
|
|
607
617
|
with_forecast=True,
|
608
618
|
with_measurements=False,
|
609
619
|
with_report=False,
|
620
|
+
with_uv=True,
|
610
621
|
):
|
611
622
|
if with_measurements and self.has_measurement(self.station_id):
|
612
623
|
self.download_latest_report()
|
@@ -620,6 +631,8 @@ class Weather:
|
|
620
631
|
or force_hourly
|
621
632
|
):
|
622
633
|
self.download_latest_kml(self.station_id, force_hourly)
|
634
|
+
if with_uv:
|
635
|
+
self.download_uv_index()
|
623
636
|
|
624
637
|
def get_weather_type(self, kmlTree, weatherDataType: WeatherDataType):
|
625
638
|
"""Parses the kml-File to the requested value and returns the items as array"""
|
@@ -849,8 +862,10 @@ class Weather:
|
|
849
862
|
uv_reports = json.loads(request.text)["content"]
|
850
863
|
# Match with existing stations
|
851
864
|
for uv_report in uv_reports:
|
852
|
-
station = get_station_by_name(
|
853
|
-
|
865
|
+
station = get_station_by_name(
|
866
|
+
self.uv_index_stations_reference_names[uv_report["city"]]
|
867
|
+
)
|
868
|
+
# uv_report.update({"lat": station[1]["lat"], "lon": station[1]["lon"]})
|
854
869
|
self.uv_reports[station[0]] = uv_report
|
855
870
|
|
856
871
|
def download_weather_report(self, region_code):
|
@@ -21,8 +21,9 @@ class WeatherBackgroundMapType(Enum):
|
|
21
21
|
KREISE = "dwd:Warngebiete_Kreise"
|
22
22
|
GEMEINDEN = "dwd:Warngebiete_Gemeinden"
|
23
23
|
SATELLIT = "dwd:bluemarble"
|
24
|
+
GEWAESSER = "dwd:Gewaesser"
|
24
25
|
|
25
|
-
def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType = WeatherBackgroundMapType.BUNDESLAENDER, image_width=520, image_height=580
|
26
|
+
def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType = WeatherBackgroundMapType.BUNDESLAENDER, image_width=520, image_height=580):
|
26
27
|
if radius_km <= 0:
|
27
28
|
raise ValueError("Radius must be greater than 0")
|
28
29
|
if latitude < -90 or latitude > 90:
|
@@ -30,12 +31,12 @@ def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType,
|
|
30
31
|
if longitude < -180 or longitude > 180:
|
31
32
|
raise ValueError("Longitude must be between -180 and 180")
|
32
33
|
radius = math.fabs(radius_km / (111.3 * math.cos(latitude)))
|
33
|
-
get_map(latitude-radius, longitude-radius, latitude+radius, longitude+radius, map_type, background_type, image_width, image_height
|
34
|
+
return get_map(latitude-radius, longitude-radius, latitude+radius, longitude+radius, map_type, background_type, image_width, image_height)
|
34
35
|
|
35
|
-
def get_germany(map_type: WeatherMapType, image_width=520, image_height=580
|
36
|
-
get_map(4.4, 46.4, 16.1, 55.6, map_type, WeatherBackgroundMapType.BUNDESLAENDER, image_width, image_height
|
36
|
+
def get_germany(map_type: WeatherMapType, image_width=520, image_height=580):
|
37
|
+
return get_map(4.4, 46.4, 16.1, 55.6, map_type, WeatherBackgroundMapType.BUNDESLAENDER, image_width, image_height)
|
37
38
|
|
38
|
-
def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, image_width=520, image_height=580
|
39
|
+
def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, image_width=520, image_height=580):
|
39
40
|
if image_width > 1200 or image_height > 1400:
|
40
41
|
raise ValueError("Width and height must not exceed 1200 and 1400 respectively. Please be kind to the DWD servers.")
|
41
42
|
|
@@ -43,4 +44,4 @@ def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: Weat
|
|
43
44
|
request = requests.get(url, stream=True)
|
44
45
|
if request.status_code == 200:
|
45
46
|
image = Image.open(BytesIO(request.content))
|
46
|
-
image
|
47
|
+
return image
|
@@ -0,0 +1 @@
|
|
1
|
+
{"10616": {"city": "Hahn", "lat": 49.95, "lon": 7.267}, "P0332": {"city": "Marienleuchte", "lat": 54.467, "lon": 11.167}, "10865": {"city": "München", "lat": 48.167, "lon": 11.533}, "10739": {"city": "Stuttgart", "lat": 48.833, "lon": 9.2}, "10487": {"city": "Dresden", "lat": 51.05, "lon": 13.733}, "10791": {"city": "Großer Arber", "lat": 49.117, "lon": 13.133}, "P0489": {"city": "Hamburg", "lat": 53.55, "lon": 9.983}, "10361": {"city": "Magdeburg", "lat": 52.117, "lon": 11.583}, "10438": {"city": "Kassel", "lat": 51.3, "lon": 9.45}, "10268": {"city": "Waren", "lat": 53.517, "lon": 12.667}, "10929": {"city": "Konstanz", "lat": 47.683, "lon": 9.183}, "10724": {"city": "Weinbiet", "lat": 49.383, "lon": 8.117}, "10427": {"city": "Kahler Asten", "lat": 51.183, "lon": 8.483}, "10637": {"city": "Frankfurt/Main", "lat": 50.05, "lon": 8.6}, "10961": {"city": "Zugspitze", "lat": 47.417, "lon": 10.983}, "10020": {"city": "List auf Sylt", "lat": 55.017, "lon": 8.417}, "P0175": {"city": "Rostock", "lat": 54.083, "lon": 12.133}, "10317": {"city": "Osnabrück", "lat": 52.25, "lon": 8.05}, "10224": {"city": "Bremen", "lat": 53.05, "lon": 8.8}, "10261": {"city": "Seehausen", "lat": 52.883, "lon": 11.733}, "10046": {"city": "Kiel", "lat": 54.383, "lon": 10.15}, "10519": {"city": "Bonn", "lat": 50.733, "lon": 7.183}, "10280": {"city": "Neubrandenburg", "lat": 53.55, "lon": 13.2}, "10763": {"city": "Nürnberg", "lat": 49.5, "lon": 11.05}, "P0150": {"city": "Sankt Peter-Ording", "lat": 54.317, "lon": 8.683}, "10454": {"city": "Wernigerode", "lat": 51.85, "lon": 10.767}, "10113": {"city": "Norderney", "lat": 53.717, "lon": 7.15}, "10803": {"city": "Freiburg", "lat": 48.017, "lon": 7.833}, "10471": {"city": "Leipzig", "lat": 51.317, "lon": 12.417}, "10655": {"city": "Würzburg", "lat": 49.767, "lon": 9.967}, "10776": {"city": "Regensburg", "lat": 49.033, "lon": 12.1}, "10389": {"city": "Berlin", "lat": 52.517, "lon": 13.417}, "10555": {"city": "Weimar", "lat": 50.983, "lon": 11.317}, "10338": {"city": "Hannover", "lat": 52.467, "lon": 9.683}, "10496": {"city": "Cottbus", "lat": 51.783, "lon": 14.317}, "10838": {"city": "Ulm", "lat": 48.383, "lon": 9.95}, "10091": {"city": "Arkona", "lat": 54.683, "lon": 13.433}, "10400": {"city": "Düsseldorf", "lat": 51.3, "lon": 6.767}}
|
{simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: simple_dwd_weatherforecast
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.27
|
4
4
|
Summary: A simple tool to retrieve a weather forecast from DWD OpenData
|
5
5
|
Home-page: https://github.com/FL550/simple_dwd_weatherforecast.git
|
6
6
|
Author: Max Fermor
|
@@ -139,7 +139,7 @@ class Weather:
|
|
139
139
|
|
140
140
|
get_uv_index(int day_from_today (values: 0-2)) # Returns the UV index for the nearest station available for today, tomorrow or the day after tomorrow
|
141
141
|
|
142
|
-
update(self, optional bool force_hourly (default: False), optional bool with_forecast (default: True), optional bool with_measurements (default: False), optional bool with_report (default: False)) # Updates the weather data
|
142
|
+
update(self, optional bool force_hourly (default: False), optional bool with_forecast (default: True), optional bool with_measurements (default: False), optional bool with_report (default: False), optional bool with_uv (default: True)) # Updates the weather data
|
143
143
|
```
|
144
144
|
|
145
145
|
#### Advanced Usage
|
@@ -166,9 +166,13 @@ You can download weather maps from the DWD GeoServer with this package. There ar
|
|
166
166
|
```python
|
167
167
|
from simple_dwd_weatherforecast import dwdmap
|
168
168
|
|
169
|
-
dwdmap.get_from_location(51.272, 8.84, radius_km=100, map_type=dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR, background_type=dwdmap.WeatherBackgroundMapType.BUNDESLAENDER
|
169
|
+
image = dwdmap.get_from_location(51.272, 8.84, radius_km=100, map_type=dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR, background_type=dwdmap.WeatherBackgroundMapType.BUNDESLAENDER)
|
170
170
|
|
171
|
-
|
171
|
+
image.save("niederschlag.png")
|
172
|
+
|
173
|
+
image = dwdmap.get_germany(map_type=dwdmap.WeatherMapType.UVINDEX, image_width=520, image_height=580)
|
174
|
+
|
175
|
+
image.save("uvindex.png")
|
172
176
|
```
|
173
177
|
|
174
178
|
#### Available methods
|
@@ -192,11 +196,11 @@ class WeatherBackgroundMapType(Enum):
|
|
192
196
|
GEMEINDEN = "dwd:Warngebiete_Gemeinden"
|
193
197
|
SATELLIT = "dwd:bluemarble"
|
194
198
|
|
195
|
-
def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height
|
199
|
+
def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height) #Returns map as pillow image with given radius from coordinates
|
196
200
|
|
197
|
-
get_germany(map_type: WeatherMapType, optional integer image_width, optional integer image_height, optional string
|
201
|
+
get_germany(map_type: WeatherMapType, optional integer image_width, optional integer image_height, optional string save_to_filename) #Returns map as pillow image of whole germany
|
198
202
|
|
199
|
-
get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height, optional string
|
203
|
+
get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height, optional string save_to_filename) #Returns map as pillow image
|
200
204
|
```
|
201
205
|
|
202
206
|
## Help and Contribution
|
{simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/RECORD
RENAMED
@@ -1,7 +1,8 @@
|
|
1
1
|
simple_dwd_weatherforecast/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
simple_dwd_weatherforecast/dwdforecast.py,sha256=
|
3
|
-
simple_dwd_weatherforecast/dwdmap.py,sha256=
|
2
|
+
simple_dwd_weatherforecast/dwdforecast.py,sha256=2yhMV4qXs8MllvL6vDXHGV20TX5811IrkjL7FnpR6Wg,33831
|
3
|
+
simple_dwd_weatherforecast/dwdmap.py,sha256=eU-z0PVeUZsSI-rFvLd8fdISHqmLxJtb0WNaeBCBQJc,2415
|
4
4
|
simple_dwd_weatherforecast/stations.json,sha256=1u8qc2CT_rVy49SAlOicGixzHln6Y0FXevuFAz2maBw,838948
|
5
|
+
simple_dwd_weatherforecast/uv_stations.json,sha256=ADenYo-aR6qbf0UFkfYr72kkFzL9HyUKe4VQ23POGF8,2292
|
5
6
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
7
|
tests/dummy_data.py,sha256=sF8pXxq8innSpRc4lW0XxGcr34dESSAoBdAf2F2D4AI,63395
|
7
8
|
tests/dummy_data_full.py,sha256=IwYoeqVX8cpfn_gE-7arXaWV9btRm_HHqka_LfKqW-E,64053
|
@@ -32,9 +33,9 @@ tests/test_stationsfile.py,sha256=slRH5N4Gznr6tkN2oMFWJbVCw3Xrma7Hvzn1lG5E-Qg,14
|
|
32
33
|
tests/test_update.py,sha256=JMdlN_lc9Zb58yU4GNrO_sOaKN9pZEx8nt4E2UeKBi0,7254
|
33
34
|
tests/test_update_hourly.py,sha256=Zx0e_E2n2Wi1yGMDN6TURzIbk_xVYaMc-7IDK1sC5UY,1668
|
34
35
|
tests/test_uv_index.py,sha256=tr6wnOyHlXT1S3yp1oeHc4-Brmc-EMEdM4mtyrdpcHg,579
|
35
|
-
tests/test_weather.py,sha256=
|
36
|
-
simple_dwd_weatherforecast-2.0.
|
37
|
-
simple_dwd_weatherforecast-2.0.
|
38
|
-
simple_dwd_weatherforecast-2.0.
|
39
|
-
simple_dwd_weatherforecast-2.0.
|
40
|
-
simple_dwd_weatherforecast-2.0.
|
36
|
+
tests/test_weather.py,sha256=U4FkTtqLcLs8k-xy6YKNM_4HVscITymURCEIUShk6iE,802
|
37
|
+
simple_dwd_weatherforecast-2.0.27.dist-info/LICENCE,sha256=27UG7gteqvSWuZlsbIq2_OAbh7VyifGGl-1zpuUoBcw,1072
|
38
|
+
simple_dwd_weatherforecast-2.0.27.dist-info/METADATA,sha256=Lo77AVfx7TRXyPIVMiHxvon5ZFuPZVeU5YN_ymGrDBc,10749
|
39
|
+
simple_dwd_weatherforecast-2.0.27.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
40
|
+
simple_dwd_weatherforecast-2.0.27.dist-info/top_level.txt,sha256=iyEobUh14Tzitx39Oi8qm0NhBrnZovl_dNKtvLUkLEM,33
|
41
|
+
simple_dwd_weatherforecast-2.0.27.dist-info/RECORD,,
|
tests/test_weather.py
CHANGED
{simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/LICENCE
RENAMED
File without changes
|
{simple_dwd_weatherforecast-2.0.25.dist-info → simple_dwd_weatherforecast-2.0.27.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|