diff --git a/simple_dwd_weatherforecast/dwdmap.py b/simple_dwd_weatherforecast/dwdmap.py index ff0b70b..ea54e9a 100644 --- a/simple_dwd_weatherforecast/dwdmap.py +++ b/simple_dwd_weatherforecast/dwdmap.py @@ -15,6 +15,7 @@ class WeatherMapType(Enum): WARNUNGEN_GEMEINDEN = "dwd:Warnungen_Gemeinden" WARNUNGEN_KREISE = "dwd:Warnungen_Landkreise" + class WeatherBackgroundMapType(Enum): LAENDER = "dwd:Laender" BUNDESLAENDER = "dwd:Warngebiete_Bundeslaender" @@ -23,7 +24,16 @@ 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): + +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,17 +41,46 @@ 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))) - return get_map(latitude-radius, longitude-radius, latitude+radius, longitude+radius, map_type, background_type, image_width, image_height) + 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, + background_type: WeatherBackgroundMapType = WeatherBackgroundMapType.BUNDESLAENDER, + image_width=520, + image_height=580, +): + return get_map( + 4.4, 46.4, 16.1, 55.6, map_type, background_type, image_width, image_height + ) -def get_germany(map_type: WeatherMapType, background_type: WeatherBackgroundMapType = WeatherBackgroundMapType.BUNDESLAENDER, image_width=520, image_height=580): - return get_map(4.4, 46.4, 16.1, 55.6, map_type, background_type, image_width, image_height) -def get_map(minx,miny,maxx,maxy, map_type: WeatherMapType, background_type: WeatherBackgroundMapType, image_width=520, image_height=580): +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.") + raise ValueError( + "Width and height must not exceed 1200 and 1400 respectively. Please be kind to the DWD servers." + ) url = f"https://maps.dwd.de/geoserver/dwd/wms?service=WMS&version=1.1.0&request=GetMap&layers={map_type.value},{background_type.value}&bbox={minx},{miny},{maxx},{maxy}&width={image_width}&height={image_height}&srs=EPSG:4326&styles=&format=image/png" request = requests.get(url, stream=True) if request.status_code == 200: image = Image.open(BytesIO(request.content)) - return image \ No newline at end of file + return image