diff --git a/README.md b/README.md index 2d1711d..4db8148 100644 --- a/README.md +++ b/README.md @@ -181,13 +181,50 @@ class WeatherBackgroundMapType(Enum): GEMEINDEN = "dwd:Warngebiete_Gemeinden" SATELLIT = "dwd:bluemarble" -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 +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 get_germany(map_type: WeatherMapType, optional WeatherBackgroundMapType background_type, optional integer image_width, optional integer image_height, optional string save_to_filename) #Returns map as pillow image of whole germany 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 ``` + +### Image loop + +There is also the possibility to retrieve multiple images as a loop. This can be done by the class ImageLoop. + + +#### Usage example +```python +from simple_dwd_weatherforecast import dwdmap + +maploop = dwdmap.ImageLoop( + dwdmap.germany_boundaries.minx, + dwdmap.germany_boundaries.miny, + dwdmap.germany_boundaries.maxx, + dwdmap.germany_boundaries.maxy, + dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR, + dwdmap.WeatherBackgroundMapType.BUNDESLAENDER, + steps=5, +) + +for image in enumerate(maploop._images): + image[1].save(f"image{image[0]}.png") + +``` + +#### Available methods + +```python +ImageLoop(minx: float, miny: float, maxx: float, maxy: float, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, + steps: int = 6, image_width: int = 520,image_height: int = 580) -> ImageLoop + +get_images() -> Iterable[ImageFile.ImageFile] # Returns the image loop + +update() # Updates the loop to the most recent files + +``` + ## Help and Contribution Feel free to open an issue if you find one and I will do my best to help you. If you want to contribute, your help is appreciated! If you want to add a new feature, add a pull request first so we can chat about the details. diff --git a/setup.py b/setup.py index be693d6..56527e6 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="simple_dwd_weatherforecast", - version="2.0.34", + version="2.1.0", author="Max Fermor", description="A simple tool to retrieve a weather forecast from DWD OpenData", long_description=long_description, diff --git a/simple_dwd_weatherforecast/dwdmap.py b/simple_dwd_weatherforecast/dwdmap.py index 32ea7a8..b3144f5 100644 --- a/simple_dwd_weatherforecast/dwdmap.py +++ b/simple_dwd_weatherforecast/dwdmap.py @@ -160,19 +160,17 @@ def _full_reload(self): def update(self): now = get_time_last_5_min(datetime.now(timezone.utc)) - # wenn last update länger her als buffer, dann lade alles neu + # If last update is older than the buffer can hold, reload the whole buffer if now - self._last_update > self._steps * timedelta(minutes=5): self._full_reload() - # wenn last update innerhalb des buffers ist, dann lade die bilder vom ältesten zum neuesten neu in den buffer + # Update the buffer and fetch only the new images else: while now > self._last_update: self._last_update += timedelta(minutes=5) self._images.append(self._get_image(self._last_update)) def _get_image(self, date: datetime) -> ImageFile.ImageFile: - print(f"{date.strftime('%Y-%m-%dT%H:%M:00.0Z')}") url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.0&request=GetMap&layers={self._map_type.value},{self._background_type.value}&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")}" - print(url) request = requests.get(url, stream=True) if request.status_code != 200: raise ConnectionError("Error during image request from DWD servers")