From 2ca00ef3a0e66738fc462daf905c661082dd0c33 Mon Sep 17 00:00:00 2001 From: mrbwburns <> Date: Sat, 20 Jan 2024 16:18:03 +0100 Subject: [PATCH] add weather icons cache folder + .gitignore --- icons/weather_icons/owm_icons_cache/.gitignore | 1 + icons/weather_icons/weather_icons.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 icons/weather_icons/owm_icons_cache/.gitignore diff --git a/icons/weather_icons/owm_icons_cache/.gitignore b/icons/weather_icons/owm_icons_cache/.gitignore new file mode 100644 index 0000000..aab52d9 --- /dev/null +++ b/icons/weather_icons/owm_icons_cache/.gitignore @@ -0,0 +1 @@ +*.png \ No newline at end of file diff --git a/icons/weather_icons/weather_icons.py b/icons/weather_icons/weather_icons.py index 4831da8..e365d2e 100644 --- a/icons/weather_icons/weather_icons.py +++ b/icons/weather_icons/weather_icons.py @@ -4,6 +4,13 @@ import urllib from PIL import Image +HERE = os.path.dirname(os.path.abspath(__file__)) +OWM_ICONS_CACHE = os.path.join(HERE, "owm_icons_cache/") + +if not os.path.exists(OWM_ICONS_CACHE): + os.mkdir(OWM_ICONS_CACHE) + + def get_weather_icon(icon_name, size) -> Image: """ Gets the requested weather icon as Image and returns it in the requested size @@ -14,8 +21,8 @@ def get_weather_icon(icon_name, size) -> Image: :return: the resized weather icon """ - weatherdir = os.path.dirname(os.path.abspath(__file__)) - iconpath = os.path.join(weatherdir, "owm_icons_cache", f"{icon_name}.png") + + iconpath = os.path.join(OWM_ICONS_CACHE, f"{icon_name}.png") if not os.path.exists(iconpath): urllib.request.urlretrieve(url=f"https://openweathermap.org/img/wn/{icon_name}@2x.png", filename=f"{iconpath}")