Fix weather alerts

This commit is contained in:
nemunaire 2024-05-18 17:54:25 +02:00
parent b3f79020f4
commit 1893e7c201

View File

@ -361,30 +361,38 @@ class WeatherAlerts:
def gen_alerts(self): def gen_alerts(self):
alerts = [] alerts = []
lastStartTime = 0
lastEndTime = 0
for alert in WeatherAPI().get_alerts(): for alert in WeatherAPI().get_alerts():
if alert["severity"] == "Moderate":
icon = "weather/wi-small-craft-advisory.png"
elif alert["severity"] != "Moderate":
icon = "weather/wi-gale-warning.png" icon = "weather/wi-gale-warning.png"
else: startTime = WeatherAPI().read_timestamp(alert["start"])
icon = None endTime = WeatherAPI().read_timestamp(alert["end"]-1)
vendTime = WeatherAPI().read_timestamp(alert["end"])
startTime = WeatherAPI().read_timestamp(alert["effective"])
endTime = WeatherAPI().read_timestamp(alert["expires"])
# Show alert timing if under a day # Show alert timing if under a day
if startTime.hour != endTime.hour: if startTime.hour != vendTime.hour:
subtitle = startTime.strftime(("%x " if startTime.day != datetime.now().day else "") + "%X") + " - " + endTime.strftime(("%x " if startTime.day != endTime.day else "") + "%X") subtitle = startTime.strftime(("%x " if startTime.day != datetime.now().day else "") + "%X") + " - " + endTime.strftime(("%x " if startTime.day != endTime.day else "") + "%X")
elif startTime.day != datetime.now().day: elif startTime.day != datetime.now().day:
subtitle = startTime.strftime("%x") subtitle = startTime.strftime("%x")
else: else:
subtitle = "" subtitle = ""
if len(alerts) >= 1 and alerts[len(alerts)-1]["title"] == alert["event"]:
startTime = lastStartTime
if startTime.hour != vendTime.hour:
alerts[len(alerts)-1]["subtitle"] = startTime.strftime(("%x " if startTime.day != datetime.now().day else "") + "%X") + " - " + endTime.strftime(("%x " if startTime.day != endTime.day else "") + "%X")
elif startTime.day != datetime.now().day:
alerts[len(alerts)-1]["subtitle"] = startTime.strftime("%x")
continue
lastStartTime = startTime
lastEndTime = vendTime
alerts.append({ alerts.append({
"icon": icon, "icon": icon,
"title": alert["headline"], "title": alert["event"],
"subtitle": subtitle, "subtitle": subtitle,
"description": alert["desc"], "description": alert["description"],
}) })
return alerts return alerts