simple-dwd-weatherforecast 2.1.14__py3-none-any.whl → 2.1.16__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.
@@ -14,14 +14,22 @@ import arrow
14
14
  import requests
15
15
  from lxml import etree
16
16
 
17
- with importlib.resources.files("simple_dwd_weatherforecast").joinpath( # type: ignore
18
- "stations.json"
19
- ).open("r", encoding="utf-8") as file:
17
+ with (
18
+ importlib.resources.files("simple_dwd_weatherforecast")
19
+ .joinpath( # type: ignore
20
+ "stations.json"
21
+ )
22
+ .open("r", encoding="utf-8") as file
23
+ ):
20
24
  stations = json.load(file)
21
25
 
22
- with importlib.resources.files("simple_dwd_weatherforecast").joinpath( # type: ignore
23
- "uv_stations.json"
24
- ).open("r", encoding="utf-8") as file:
26
+ with (
27
+ importlib.resources.files("simple_dwd_weatherforecast")
28
+ .joinpath( # type: ignore
29
+ "uv_stations.json"
30
+ )
31
+ .open("r", encoding="utf-8") as file
32
+ ):
25
33
  uv_stations = json.load(file)
26
34
 
27
35
 
@@ -483,12 +491,13 @@ class Weather:
483
491
  value = None
484
492
  for item in weather_data:
485
493
  value_new = item[weatherDataType.value[0]]
486
- if value_new:
487
- if not value:
494
+ if value_new is not None:
495
+ if value is None:
488
496
  value = -9999999
489
497
  if value_new > value:
490
498
  value = value_new
491
- if value:
499
+
500
+ if value is not None:
492
501
  return round(value, 2)
493
502
  return None
494
503
 
@@ -520,13 +529,13 @@ class Weather:
520
529
  value = None
521
530
  for item in weather_data:
522
531
  value_new = item[weatherDataType.value[0]]
523
- if value_new:
524
- if not value:
532
+ if value_new is not None:
533
+ if value is None:
525
534
  value = 9999999
526
535
  if value_new < value:
527
536
  value = value_new
528
537
 
529
- if value:
538
+ if value is not None:
530
539
  return round(value, 2)
531
540
  return None
532
541
 
@@ -558,7 +567,7 @@ class Weather:
558
567
  value_sum = 0.0
559
568
  for item in weather_data:
560
569
  value = item[weatherDataType.value[0]]
561
- if value:
570
+ if value is not None:
562
571
  value_sum += float(value)
563
572
  return round(value_sum, 2)
564
573
 
@@ -9,7 +9,8 @@ from datetime import datetime, timedelta, timezone
9
9
 
10
10
 
11
11
  class WeatherMapType(Enum):
12
- NIEDERSCHLAGSRADAR = "dwd:Niederschlagsradar,dwd:NCEW_EU"
12
+ NIEDERSCHLAGSRADAR = "dwd:Niederschlagsradar"
13
+ BLITZSCHLAG = "dwd:NCEW_EU"
13
14
  MAXTEMP = "dwd:GefuehlteTempMax"
14
15
  UVINDEX = "dwd:UVI_CS"
15
16
  POLLENFLUG = "dwd:Pollenflug"
@@ -158,7 +159,7 @@ def get_map(
158
159
  layers = f"{background_type.value}, {map_type.value}"
159
160
  else:
160
161
  layers = f"{map_type.value}, {background_type.value}"
161
- url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.0&request=GetMap&layers={layers}&bbox={minx},{miny},{maxx},{maxy}&width={image_width}&height={image_height}&srs=EPSG:4326&styles=&format=image/png"
162
+ url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.1&request=GetMap&layers={layers}&bbox={minx},{miny},{maxx},{maxy}&width={image_width}&height={image_height}&srs=EPSG:4326&styles=&format=image/png"
162
163
  request = requests.get(url, stream=True)
163
164
  if request.status_code == 200:
164
165
  image = Image.open(BytesIO(request.content))
@@ -237,7 +238,13 @@ class ImageLoop:
237
238
 
238
239
  while now > self._last_update:
239
240
  self._last_update += timedelta(minutes=5)
240
- self._images.append(self._get_image(self._last_update))
241
+ # Lightning in the NCEW_EU layer is only available in the last 5 minutes
242
+ self._images.append(
243
+ self._get_image(
244
+ self._last_update,
245
+ with_lightning=(now - self._last_update) < timedelta(minutes=5),
246
+ )
247
+ )
241
248
 
242
249
  def update(self):
243
250
  now = get_time_last_5_min(datetime.now(timezone.utc))
@@ -249,23 +256,31 @@ class ImageLoop:
249
256
  else:
250
257
  while now > self._last_update:
251
258
  self._last_update += timedelta(minutes=5)
252
- self._images.append(self._get_image(self._last_update))
259
+ self._images.append(
260
+ self._get_image(self._last_update, with_lightning=True)
261
+ )
253
262
 
254
263
  def _get_image(
255
264
  self,
256
265
  date: datetime,
266
+ with_lightning: bool = False,
257
267
  ) -> ImageFile.ImageFile:
268
+ # Lightning in the NCEW_EU layer is only available in the last 5 minutes
269
+ layer = self._map_type.value
270
+ if with_lightning:
271
+ layer += ",dwd:NCEW_EU"
258
272
  if self._background_type in [
259
273
  WeatherBackgroundMapType.SATELLIT,
260
274
  WeatherBackgroundMapType.KREISE,
261
275
  WeatherBackgroundMapType.GEMEINDEN,
262
276
  ]:
263
- layers = f"{self._background_type.value}, {self._map_type.value}"
277
+ layers = f"{self._background_type.value}, {layer}"
264
278
  else:
265
- layers = f"{self._map_type.value}, {self._background_type.value}"
266
- url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.0&request=GetMap&layers={layers}&bbox={self._minx},{self._miny},{self._maxx},{self._maxy}&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')}"
279
+ layers = f"{layer}, {self._background_type.value}"
280
+
281
+ url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.1&request=GetMap&layers={layers}&bbox={self._minx},{self._miny},{self._maxx},{self._maxy}&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')}"
267
282
  request = requests.get(url, stream=True)
268
- if request.status_code != 200:
283
+ if request.status_code != 200 or request.headers["content-type"] != "image/png":
269
284
  raise ConnectionError("Error during image request from DWD servers")
270
285
  image = Image.open(BytesIO(request.content))
271
286
  if self.dark_mode:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: simple_dwd_weatherforecast
3
- Version: 2.1.14
3
+ Version: 2.1.16
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
@@ -1,6 +1,6 @@
1
1
  simple_dwd_weatherforecast/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- simple_dwd_weatherforecast/dwdforecast.py,sha256=emM_zYQ0fOZhDIDz60yCXN8vCI3Nsp9VKq8tcOn3TZQ,38973
3
- simple_dwd_weatherforecast/dwdmap.py,sha256=Ktokd5Yyj7FJKKlbJrqX8mj24v7IN_pLdY4rk6FbNUY,11894
2
+ simple_dwd_weatherforecast/dwdforecast.py,sha256=uZRWMN9RIPvC9r47JAdw_AiP9V9M2rQxh_pOsVF15Sw,39094
3
+ simple_dwd_weatherforecast/dwdmap.py,sha256=ckDP6MOTfzwvz01gjzkimIreVGUU7WqFV1CRoCQ9Z1k,12452
4
4
  simple_dwd_weatherforecast/stations.json,sha256=1u8qc2CT_rVy49SAlOicGixzHln6Y0FXevuFAz2maBw,838948
5
5
  simple_dwd_weatherforecast/uv_stations.json,sha256=ADenYo-aR6qbf0UFkfYr72kkFzL9HyUKe4VQ23POGF8,2292
6
6
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -10,7 +10,7 @@ tests/dummy_uv.py,sha256=TM1TwvNq_ea4WgIJyYsNAEXZJTx1dXH1ZVrW_LfLBLg,4548
10
10
  tests/test_get_daily_avg.py,sha256=MNd7u9Y7_E6SIyxg59EKfdKx4QJ7R_WT5wvRgm7Gzks,2315
11
11
  tests/test_get_daily_condition.py,sha256=9Qrhv14-vLnLz0N0FWG7Mv6_iEbNPqrHDDWWNQNydU0,2298
12
12
  tests/test_get_daily_max.py,sha256=schjGJDflg1YEQSdfRndw2NT4AvrVheSDveyVZrFySM,2220
13
- tests/test_get_daily_min.py,sha256=GzqlOfLdwLqGLYVeAJ0fbK1JRq-_fT7z6Gea74lSY7E,2224
13
+ tests/test_get_daily_min.py,sha256=3q-l6EpyIDwX7zzOZGJ9OFyD7ZM1JYMAhXfbil-yoJA,2223
14
14
  tests/test_get_daily_sum.py,sha256=UEntbPwGSleHocu0587WnuC5ijptQtzVNreR1d6yoM0,2221
15
15
  tests/test_get_day_values.py,sha256=hDphH7fekfcWX7slJUF1QiH3B7te23nHiS5-Fro3HY4,31013
16
16
  tests/test_get_forecast_condition.py,sha256=YVapxXH5Svq5P7XvWn48n19hriQ1-7CSezuGc6DswJQ,2866
@@ -35,8 +35,8 @@ tests/test_update.py,sha256=AIzzHMxcjwQjeTB0l3YFgB7HkGDbuqiHofwy41mS0m4,7440
35
35
  tests/test_update_hourly.py,sha256=7Zl8ml3FTdqw3_Qwr_Tz-sWTzypvrBWmxeig2Vwp_ZQ,1781
36
36
  tests/test_uv_index.py,sha256=tr6wnOyHlXT1S3yp1oeHc4-Brmc-EMEdM4mtyrdpcHg,579
37
37
  tests/test_weather.py,sha256=ZyX4ldUoJpJp7YpiNQwU6Od-nYRay-3qcaDJdNq8fhY,780
38
- simple_dwd_weatherforecast-2.1.14.dist-info/LICENCE,sha256=27UG7gteqvSWuZlsbIq2_OAbh7VyifGGl-1zpuUoBcw,1072
39
- simple_dwd_weatherforecast-2.1.14.dist-info/METADATA,sha256=yOmvr1psI8zmU1eZstNMmOeEoc8w66wpig4Ljiv2nlY,12828
40
- simple_dwd_weatherforecast-2.1.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
41
- simple_dwd_weatherforecast-2.1.14.dist-info/top_level.txt,sha256=iyEobUh14Tzitx39Oi8qm0NhBrnZovl_dNKtvLUkLEM,33
42
- simple_dwd_weatherforecast-2.1.14.dist-info/RECORD,,
38
+ simple_dwd_weatherforecast-2.1.16.dist-info/LICENCE,sha256=27UG7gteqvSWuZlsbIq2_OAbh7VyifGGl-1zpuUoBcw,1072
39
+ simple_dwd_weatherforecast-2.1.16.dist-info/METADATA,sha256=F-73LROsSo1La1YgnrUPxPmi7pwzxipgGSnAT4LaN2U,12828
40
+ simple_dwd_weatherforecast-2.1.16.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
41
+ simple_dwd_weatherforecast-2.1.16.dist-info/top_level.txt,sha256=iyEobUh14Tzitx39Oi8qm0NhBrnZovl_dNKtvLUkLEM,33
42
+ simple_dwd_weatherforecast-2.1.16.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -34,7 +34,7 @@ class Weather_get_daily_min(unittest.TestCase):
34
34
  test_time = datetime(2020, 11, 6, 10, 0)
35
35
  self.assertEqual(
36
36
  self.dwd_weather.get_daily_min(WeatherDataType.PRECIPITATION, test_time),
37
- 0.01,
37
+ 0.0,
38
38
  )
39
39
 
40
40
  @patch("simple_dwd_weatherforecast.dwdforecast.Weather.update", return_value=None)