Replace precipitation probability by UV index when no precicipation

This commit is contained in:
nemunaire 2022-08-11 15:19:51 +02:00
parent aa0a66fa0d
commit 450f1eb9dd

View File

@ -156,16 +156,24 @@ class WeatherRainModule:
thisdayweather = WeatherAPI().get_daily()["data"][0]
gauge = pygal.SolidGauge(half_pie=True, inner_radius=0.70, width=width, height=height*1.55, style=config.pygal_custom_style, show_legend=False, margin_top=-height*0.6, margin_left=1, margin_right=1)
percent_formatter = lambda x: '{:.10g}%'.format(x)
gauge.value_formatter = percent_formatter
gauge.add('Rain', [{'value': thisdayweather["precipProbability"] * 100 + 1}])
if thisdayweather["precipProbability"] == 0 and thisdayweather["uvIndex"] > 4:
gauge.add('Index UV', [{'value': thisdayweather["uvIndex"] * 10}])
icon_path = "wi-hot.png"
else:
gauge.add('Pluie', [{'value': thisdayweather["precipProbability"] * 100 + 1}])
if thisdayweather["precipProbability"] > 0:
icon_path = "wi-umbrella.png"
else:
icon_path = "wi-na.png"
image = Image.open(io.BytesIO(gauge.render_to_png()))
icon = Image.open("icons/wi-umbrella.png").resize((int(height/1.25), int(height/1.25)))
image.paste(icon, (int(width/2-height/2.5), int(height-height/1.25)), icon)
if icon_path:
icon = Image.open("icons/" + icon_path).resize((int(height/1.25), int(height/1.25)))
image.paste(icon, (int(width/2-height/2.5), int(height-height/1.25)), icon)
return image