Fix weather alerts
This commit is contained in:
parent
b3f79020f4
commit
1893e7c201
@ -361,30 +361,38 @@ class WeatherAlerts:
|
||||
|
||||
def gen_alerts(self):
|
||||
alerts = []
|
||||
lastStartTime = 0
|
||||
lastEndTime = 0
|
||||
|
||||
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"
|
||||
else:
|
||||
icon = None
|
||||
icon = "weather/wi-gale-warning.png"
|
||||
startTime = WeatherAPI().read_timestamp(alert["start"])
|
||||
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
|
||||
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")
|
||||
elif startTime.day != datetime.now().day:
|
||||
subtitle = startTime.strftime("%x")
|
||||
else:
|
||||
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({
|
||||
"icon": icon,
|
||||
"title": alert["headline"],
|
||||
"title": alert["event"],
|
||||
"subtitle": subtitle,
|
||||
"description": alert["desc"],
|
||||
"description": alert["description"],
|
||||
})
|
||||
|
||||
return alerts
|
||||
|
Loading…
Reference in New Issue
Block a user