simple-dwd-weatherforecast 3.0.2__tar.gz → 3.0.4__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.
Files changed (47) hide show
  1. {simple_dwd_weatherforecast-3.0.2/simple_dwd_weatherforecast.egg-info → simple_dwd_weatherforecast-3.0.4}/PKG-INFO +1 -1
  2. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/setup.py +1 -1
  3. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast/dwdforecast.py +1 -2
  4. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast/dwdmap.py +46 -44
  5. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4/simple_dwd_weatherforecast.egg-info}/PKG-INFO +1 -1
  6. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/LICENCE +0 -0
  7. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/README.md +0 -0
  8. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/setup.cfg +0 -0
  9. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast/__init__.py +0 -0
  10. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast/stations.json +0 -0
  11. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast/uv_stations.json +0 -0
  12. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast.egg-info/SOURCES.txt +0 -0
  13. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast.egg-info/dependency_links.txt +0 -0
  14. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast.egg-info/requires.txt +0 -0
  15. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/simple_dwd_weatherforecast.egg-info/top_level.txt +0 -0
  16. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/__init__.py +0 -0
  17. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/dummy_data.py +0 -0
  18. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/dummy_data_full.py +0 -0
  19. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/dummy_uv.py +0 -0
  20. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_daily_avg.py +0 -0
  21. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_daily_condition.py +0 -0
  22. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_daily_max.py +0 -0
  23. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_daily_min.py +0 -0
  24. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_daily_sum.py +0 -0
  25. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_day_values.py +0 -0
  26. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_forecast_condition.py +0 -0
  27. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_forecast_data.py +0 -0
  28. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_station_name.py +0 -0
  29. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_timeframe_avg.py +0 -0
  30. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_timeframe_condition.py +0 -0
  31. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_timeframe_max.py +0 -0
  32. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_timeframe_min.py +0 -0
  33. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_timeframe_sum.py +0 -0
  34. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_get_timeframe_values.py +0 -0
  35. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_is_in_timerange.py +0 -0
  36. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_is_valid_timeframe.py +0 -0
  37. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_location_tools.py +0 -0
  38. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_map.py +0 -0
  39. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_parsekml.py +0 -0
  40. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_region.py +0 -0
  41. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_reported_weather.py +0 -0
  42. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_station.py +0 -0
  43. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_stationsfile.py +0 -0
  44. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_update.py +0 -0
  45. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_update_hourly.py +0 -0
  46. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_uv_index.py +0 -0
  47. {simple_dwd_weatherforecast-3.0.2 → simple_dwd_weatherforecast-3.0.4}/tests/test_weather.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple_dwd_weatherforecast
3
- Version: 3.0.2
3
+ Version: 3.0.4
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
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="simple_dwd_weatherforecast",
8
- version="v3.0.2",
8
+ version="v3.0.4",
9
9
  author="Max Fermor",
10
10
  description="A simple tool to retrieve a weather forecast from DWD OpenData",
11
11
  long_description=long_description,
@@ -421,8 +421,7 @@ class Weather:
421
421
 
422
422
  def get_reported_weather(self, weatherDataType: WeatherDataType, shouldUpdate=True):
423
423
  if not self.has_measurement(self.station_id):
424
- print("no report for this station available")
425
- return None
424
+ raise ValueError("No report for this station available")
426
425
  if shouldUpdate:
427
426
  self.update(with_measurements=True)
428
427
  if self.report_data is not None:
@@ -182,8 +182,10 @@ def get_map(
182
182
  layers = f"{','.join(special_layers)},{map_layers},{','.join(other_layers)}".lstrip(
183
183
  ","
184
184
  ).rstrip(",")
185
-
186
- url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.3.0&request=GetMap&layers={layers}&bbox={miny},{minx},{maxy},{maxx}&width={image_width}&height={image_height}&srs=EPSG:4326&styles=&format=image/png"
185
+ bgcolor = "0xFFFFFF"
186
+ if dark_mode:
187
+ bgcolor = "0x1C1C1C"
188
+ url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.3.0&request=GetMap&layers={layers}&bbox={miny},{minx},{maxy},{maxx}&width={image_width}&height={image_height}&srs=EPSG:4326&styles=&format=image/png&bgcolor={bgcolor}"
187
189
 
188
190
  request = requests.get(url, stream=True)
189
191
  if request.status_code == 200:
@@ -193,18 +195,6 @@ def get_map(
193
195
  raise RuntimeError(
194
196
  f"Error during image request from DWD servers: {url}"
195
197
  ) from e
196
- if dark_mode:
197
- new_image_data = []
198
- for item in image.getdata(): # type: ignore
199
- if item[0] == 255 and item[1] == 255 and item[2] == 255:
200
- new_image_data.append((28, 28, 28))
201
- elif item[0] == 85 and item[1] == 85 and item[2] == 85:
202
- new_image_data.append((155, 155, 155))
203
- else:
204
- new_image_data.append(item)
205
-
206
- # update image data
207
- image.putdata(new_image_data)
208
198
  image = draw_marker(image, ImageBoundaries(minx, maxx, miny, maxy), markers)
209
199
  return image
210
200
  else:
@@ -270,15 +260,7 @@ class ImageLoop:
270
260
  now = get_time_last_5_min(datetime.now(timezone.utc))
271
261
  self._last_update = now - timedelta(minutes=5) * self._steps
272
262
 
273
- while now > self._last_update:
274
- self._last_update += timedelta(minutes=5)
275
- # Lightning in the NCEW_EU layer is only available in the last 5 minutes
276
- self._images.append(
277
- self._get_image(
278
- self._last_update,
279
- with_lightning=(now - self._last_update) < timedelta(minutes=5),
280
- )
281
- )
263
+ self._load_images(now)
282
264
 
283
265
  def update(self):
284
266
  now = get_time_last_5_min(datetime.now(timezone.utc))
@@ -288,11 +270,38 @@ class ImageLoop:
288
270
  self._full_reload()
289
271
  # Update the buffer and fetch only the new images
290
272
  else:
291
- while now > self._last_update:
292
- self._last_update += timedelta(minutes=5)
293
- self._images.append(
294
- self._get_image(self._last_update, with_lightning=True)
273
+ self._load_images(now)
274
+
275
+ def _load_images(self, now):
276
+ while now > self._last_update:
277
+ self._last_update += timedelta(minutes=5)
278
+ # Lightning in the NCEW_EU layer is only available in the last 5 minutes
279
+ try:
280
+ image = self._get_image(
281
+ self._last_update,
282
+ with_lightning=(now - self._last_update) < timedelta(minutes=5),
295
283
  )
284
+ except ConnectionError as e:
285
+ raise ConnectionAbortedError(
286
+ f"Connection to DWD map servers failed: {e}"
287
+ )
288
+ except RuntimeError as e:
289
+ raise RuntimeError(f"Error: {e}") from e
290
+ except TypeError:
291
+ try:
292
+ image = self._get_image(
293
+ self._last_update,
294
+ with_lightning=False,
295
+ )
296
+ except ConnectionError as e:
297
+ raise ConnectionAbortedError(
298
+ f"Connection to DWD map servers failed: {e}"
299
+ )
300
+ except TypeError as e:
301
+ raise TypeError(
302
+ f"Unexpected content type: {e}. Please check the DWD map servers."
303
+ ) from e
304
+ self._images.append(image)
296
305
 
297
306
  def _get_image(
298
307
  self,
@@ -330,28 +339,21 @@ class ImageLoop:
330
339
  ","
331
340
  ).rstrip(",")
332
341
  )
333
- url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.3.0&request=GetMap&layers={layers}&bbox={self._miny},{self._minx},{self._maxy},{self._maxx}&width={self._image_width}&height={self._image_height}&srs=EPSG:4326&styles=&format=image/png&TIME={date.strftime('%Y-%m-%dT%H:%M:00.0Z')}"
342
+ bgcolor = "0xFFFFFF"
343
+ if self.dark_mode:
344
+ bgcolor = "0x1C1C1C"
345
+ url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.3.0&request=GetMap&layers={layers}&bbox={self._miny},{self._minx},{self._maxy},{self._maxx}&width={self._image_width}&height={self._image_height}&srs=EPSG:4326&styles=&format=image/png&TIME={date.strftime('%Y-%m-%dT%H:%M:00.0Z')}&bgcolor={bgcolor}"
334
346
  request = requests.get(url, stream=True)
335
- if request.status_code != 200 or request.headers["content-type"] != "image/png":
347
+ if request.status_code != 200:
336
348
  raise ConnectionError(f"Error during image request from DWD servers: {url}")
349
+ elif request.headers["content-type"] != "image/png":
350
+ raise TypeError(
351
+ f"Unexpected content type: {request.headers['content-type']}"
352
+ )
337
353
  try:
338
354
  image = Image.open(BytesIO(request.content))
339
355
  except Exception as e:
340
- raise RuntimeError(
341
- f"Error during image request from DWD servers: {url}"
342
- ) from e
343
- if self.dark_mode:
344
- new_image_data = []
345
- for item in image.getdata(): # type: ignore
346
- if item[0] == 255 and item[1] == 255 and item[2] == 255:
347
- new_image_data.append((28, 28, 28))
348
- elif item[0] == 85 and item[1] == 85 and item[2] == 85:
349
- new_image_data.append((155, 155, 155))
350
- else:
351
- new_image_data.append(item)
352
-
353
- # update image data
354
- image.putdata(new_image_data)
356
+ raise RuntimeError(f"Error during image parsing: {url}") from e
355
357
  image = draw_marker(
356
358
  image,
357
359
  ImageBoundaries(self._minx, self._maxx, self._miny, self._maxy),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple_dwd_weatherforecast
3
- Version: 3.0.2
3
+ Version: 3.0.4
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