add weather icons cache folder + .gitignore

This commit is contained in:
mrbwburns 2024-01-20 16:18:03 +01:00
parent 4b2a0d1957
commit 2ca00ef3a0
2 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1 @@
*.png

View File

@ -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}")