Compare commits

..

No commits in common. "adbd46f715fa0604a6957d2a6ff21ac0c7a60092" and "2530fb4649135ca38b903878a6caa9a98a27955b" have entirely different histories.

2 changed files with 38 additions and 57 deletions

View file

@ -180,7 +180,7 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, ex
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580))
if expand_alerts and more_alerts > 0:
mod, more_alerts = AlertsModule(config, alerts, ignore_module).draw_module(config, 480, 785 - NEXT_STOP_Y - occuped_space)
mod, more_alerts = AlertsModule(alerts, ignore_module).draw_module(config, 480, 785 - NEXT_STOP_Y - occuped_space)
image.paste(mod, (0, NEXT_STOP_Y + occuped_space), mod)

View file

@ -87,7 +87,7 @@ class IDFMAPI:
self.fnt_R_path = os.path.join(config.fonts_dir, IDFMAPI.fnt_R_path)
self.fnt_RB_path = os.path.join(config.fonts_dir, IDFMAPI.fnt_RB_path)
self.baseurl = "https://prim.iledefrance-mobilites.fr/marketplace/disruptions_bulk"
self.baseurl = "https://prim.iledefrance-mobilites.fr/marketplace/v2"
self.apikey = apikey or os.environ["TOKEN_IDFM"]
self._cached_file = ".ratp-%s.cache"
@ -156,7 +156,7 @@ class IDFMAPI:
if statinfo is None or datetime.fromtimestamp(statinfo.st_mtime, tz=timezone.utc) + timedelta(minutes=self.cache_timeout) < datetime.now(tz=timezone.utc):
# Do the request and save it
req = urllib.request.Request(self.baseurl + "/disruptions/v2")
req = urllib.request.Request(self.baseurl + "/navitia/line_reports/line_reports?count=2000")
req.headers["apikey"] = self.apikey
try:
with urllib.request.urlopen(req) as f:
@ -192,25 +192,15 @@ class IDFMAPI:
return ret
def get_line_weather(self, res, disruptions, mode, line):
for l in res["lines"]:
if l["id"] == "line:IDFM:" + IDFMAPI.lines[mode][line]:
for impactedObject in l["impactedObjects"]:
for disruptionId in impactedObject["disruptionIds"]:
status = "past"
for ap in disruptions[disruptionId]["applicationPeriods"]:
end = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
if end < datetime.now():
continue
for l in res["line_reports"]:
if "line" not in l:
continue
begin = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
if begin > datetime.now():
status = "future"
continue
status = "active"
break
disruptions[disruptionId]["status"] = status
yield disruptions[disruptionId]
if "id" in l["line"]:
if l["line"]["id"] == "line:IDFM:" + IDFMAPI.lines[mode][line]:
for link in l["line"]["links"]:
if disruptions[link["id"]]["status"] != "past":
yield disruptions[link["id"]]
return None
@ -268,41 +258,40 @@ class RATPWeatherModule:
return icon
for disruption in weather[mode][line]:
if "message" not in disruption:
if "messages" not in disruption:
continue
if disruption["id"] in id_seens:
continue
if disruption["status"] != "active" and "applicationPeriods" not in disruption:
if disruption["status"] != "active" and "application_periods" not in disruption:
continue
title = ""
subtitle = ""
content = ""
oneline = False
if "applicationPeriods" in disruption:
if "application_periods" in disruption:
now = datetime.now()
yesterday = now + timedelta(days=-1)
nextweek = now + timedelta(days=1)
application_periods = []
for ap in disruption["applicationPeriods"]:
begin = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
end = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
for ap in disruption["application_periods"]:
ap["begin"] = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
ap["end"] = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
if end < now:
if ap["end"] < now:
continue
elif begin > nextweek:
elif ap["begin"] > nextweek:
continue
elif len(application_periods) > 0 and application_periods[0]["begin"] + timedelta(hours=16) < begin:
elif len(application_periods) > 0 and application_periods[0]["begin"] + timedelta(hours=16) < ap["begin"]:
continue
else:
application_periods.append({"begin": begin, "end": end})
application_periods.append(ap)
if begin < yesterday:
if ap["begin"] < yesterday:
oneline = True
if "cause" in disruption and disruption["cause"].lower() == "travaux" and begin > now:
if "cause" in disruption and disruption["cause"] == "travaux" and ap["begin"] > now:
oneline = True
if len(application_periods) == 0:
@ -313,11 +302,17 @@ class RATPWeatherModule:
elif application_periods[0]["end"] > now:
subtitle = "Fin " + whenStr(application_periods[0]["end"], now)
id_seens.append(disruption["id"])
for msg in disruption["messages"]:
if msg["channel"]["name"] == "titre":
title = msg["text"]
elif msg["channel"]["name"] == "moteur":
content = IDFMAPI.fromHTMLDisruption(msg["text"])
elif len(content) == "":
content = IDFMAPI.fromHTMLDisruption(msg["text"])
yield {
"title": disruption["title"],
"title": title,
"subtitle": subtitle,
"description": IDFMAPI.fromHTMLDisruption(disruption["message"]),
"description": content,
"icon": alert_icon(mode, line),
"oneline": oneline,
}
@ -347,27 +342,13 @@ class RATPWeatherModule:
states = []
for disruption in weather[mode][line]:
status = "past"
for ap in disruption["applicationPeriods"]:
end = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
if end < datetime.now():
continue
begin = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
if begin > datetime.now():
status = "future"
continue
status = "active"
break
if status != "active":
if disruption["status"] != "active":
continue
if "severity" in disruption:
if disruption["cause"] == "TRAVAUX":
states.append(disruption["severity"] + " " + disruption["cause"])
if disruption["cause"] == "travaux" and "line" not in [x["pt_object"]["embedded_type"] for x in disruption["impacted_objects"]]:
states.append(disruption["severity"]["effect"] + " " + disruption["cause"])
else:
states.append(disruption["severity"])
states.append(disruption["severity"]["effect"])
fill = "darkgray"
if "NO_SERVICE" in states: