From 9ba7ba4320443c852c61759a611f1b209acae544 Mon Sep 17 00:00:00 2001 From: FL550 Date: Fri, 5 Jan 2024 16:04:03 +0100 Subject: [PATCH] Removes save file to be handled by the calling function --- README.md | 14 +++++++++----- setup.py | 2 +- simple_dwd_weatherforecast/dwdmap.py | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e2f0b05..2daa707 100644 --- a/README.md +++ b/README.md @@ -149,9 +149,13 @@ You can download weather maps from the DWD GeoServer with this package. There ar ```python from simple_dwd_weatherforecast import dwdmap -dwdmap.get_from_location(51.272, 8.84, radius_km=100, map_type=dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR, background_type=dwdmap.WeatherBackgroundMapType.BUNDESLAENDER, file_name="map.png") +image = dwdmap.get_from_location(51.272, 8.84, radius_km=100, map_type=dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR, background_type=dwdmap.WeatherBackgroundMapType.BUNDESLAENDER) -dwdmap.get_germany(map_type=dwdmap.WeatherMapType.UVINDEX, width=520, height=580, filename="germany.png") +image.save("niederschlag.png") + +image = dwdmap.get_germany(map_type=dwdmap.WeatherMapType.UVINDEX, image_width=520, image_height=580) + +image.save("uvindex.png") ``` #### Available methods @@ -175,11 +179,11 @@ 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, optional string filename (default:"map.png")) #Saves map with given radius from coordinates +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_germany(map_type: WeatherMapType, optional integer image_width, optional integer image_height, optional string filename (default:"map.png")) #Saves map of whole germany +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 -get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, optional integer image_width, optional integer image_height, optional string filename (default:"map.png")) #Map retrieval +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 ``` ## Help and Contribution diff --git a/setup.py b/setup.py index c4bbc76..2691ca4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="simple_dwd_weatherforecast", - version="2.0.26", + version="2.0.27", 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 2dd12f2..53965a4 100644 --- a/simple_dwd_weatherforecast/dwdmap.py +++ b/simple_dwd_weatherforecast/dwdmap.py @@ -23,7 +23,7 @@ class WeatherBackgroundMapType(Enum): SATELLIT = "dwd:bluemarble" GEWAESSER = "dwd:Gewaesser" -def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType = WeatherBackgroundMapType.BUNDESLAENDER, image_width=520, image_height=580, filename="map.png"): +def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, background_type: WeatherBackgroundMapType = WeatherBackgroundMapType.BUNDESLAENDER, image_width=520, image_height=580): if radius_km <= 0: raise ValueError("Radius must be greater than 0") if latitude < -90 or latitude > 90: @@ -31,12 +31,12 @@ def get_from_location(longitude, latitude, radius_km, map_type: WeatherMapType, if longitude < -180 or longitude > 180: raise ValueError("Longitude must be between -180 and 180") radius = math.fabs(radius_km / (111.3 * math.cos(latitude))) - get_map(latitude-radius, longitude-radius, latitude+radius, longitude+radius, map_type, background_type, image_width, image_height, filename) + return get_map(latitude-radius, longitude-radius, latitude+radius, longitude+radius, map_type, background_type, image_width, image_height) -def get_germany(map_type: WeatherMapType, image_width=520, image_height=580, filename="map.png"): - get_map(4.4, 46.4, 16.1, 55.6, map_type, WeatherBackgroundMapType.BUNDESLAENDER, image_width, image_height, filename) +def get_germany(map_type: WeatherMapType, image_width=520, image_height=580): + return get_map(4.4, 46.4, 16.1, 55.6, map_type, WeatherBackgroundMapType.BUNDESLAENDER, image_width, image_height) -def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, image_width=520, image_height=580, filename="map.png"): +def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, image_width=520, image_height=580): if image_width > 1200 or image_height > 1400: raise ValueError("Width and height must not exceed 1200 and 1400 respectively. Please be kind to the DWD servers.") @@ -44,4 +44,4 @@ def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: Weat request = requests.get(url, stream=True) if request.status_code == 200: image = Image.open(BytesIO(request.content)) - image.save(filename) \ No newline at end of file + return image \ No newline at end of file