ratp: Use disruptions_bulk route
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8be48bb062
commit
adbd46f715
@ -87,7 +87,7 @@ class IDFMAPI:
|
|||||||
self.fnt_R_path = os.path.join(config.fonts_dir, IDFMAPI.fnt_R_path)
|
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.fnt_RB_path = os.path.join(config.fonts_dir, IDFMAPI.fnt_RB_path)
|
||||||
|
|
||||||
self.baseurl = "https://prim.iledefrance-mobilites.fr/marketplace/v2"
|
self.baseurl = "https://prim.iledefrance-mobilites.fr/marketplace/disruptions_bulk"
|
||||||
self.apikey = apikey or os.environ["TOKEN_IDFM"]
|
self.apikey = apikey or os.environ["TOKEN_IDFM"]
|
||||||
|
|
||||||
self._cached_file = ".ratp-%s.cache"
|
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):
|
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
|
# Do the request and save it
|
||||||
req = urllib.request.Request(self.baseurl + "/navitia/line_reports/line_reports?count=2000")
|
req = urllib.request.Request(self.baseurl + "/disruptions/v2")
|
||||||
req.headers["apikey"] = self.apikey
|
req.headers["apikey"] = self.apikey
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req) as f:
|
with urllib.request.urlopen(req) as f:
|
||||||
@ -192,15 +192,25 @@ class IDFMAPI:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_line_weather(self, res, disruptions, mode, line):
|
def get_line_weather(self, res, disruptions, mode, line):
|
||||||
for l in res["line_reports"]:
|
for l in res["lines"]:
|
||||||
if "line" not in l:
|
if l["id"] == "line:IDFM:" + IDFMAPI.lines[mode][line]:
|
||||||
continue
|
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
|
||||||
|
|
||||||
if "id" in l["line"]:
|
begin = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
|
||||||
if l["line"]["id"] == "line:IDFM:" + IDFMAPI.lines[mode][line]:
|
if begin > datetime.now():
|
||||||
for link in l["line"]["links"]:
|
status = "future"
|
||||||
if disruptions[link["id"]]["status"] != "past":
|
continue
|
||||||
yield disruptions[link["id"]]
|
|
||||||
|
status = "active"
|
||||||
|
break
|
||||||
|
disruptions[disruptionId]["status"] = status
|
||||||
|
yield disruptions[disruptionId]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -258,40 +268,41 @@ class RATPWeatherModule:
|
|||||||
return icon
|
return icon
|
||||||
|
|
||||||
for disruption in weather[mode][line]:
|
for disruption in weather[mode][line]:
|
||||||
if "messages" not in disruption:
|
if "message" not in disruption:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if disruption["status"] != "active" and "application_periods" not in disruption:
|
if disruption["id"] in id_seens:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if disruption["status"] != "active" and "applicationPeriods" not in disruption:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
title = ""
|
|
||||||
subtitle = ""
|
subtitle = ""
|
||||||
content = ""
|
|
||||||
oneline = False
|
oneline = False
|
||||||
|
|
||||||
if "application_periods" in disruption:
|
if "applicationPeriods" in disruption:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
yesterday = now + timedelta(days=-1)
|
yesterday = now + timedelta(days=-1)
|
||||||
nextweek = now + timedelta(days=1)
|
nextweek = now + timedelta(days=1)
|
||||||
|
|
||||||
application_periods = []
|
application_periods = []
|
||||||
for ap in disruption["application_periods"]:
|
for ap in disruption["applicationPeriods"]:
|
||||||
ap["begin"] = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
|
begin = datetime.strptime(ap["begin"], "%Y%m%dT%H%M%S")
|
||||||
ap["end"] = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
|
end = datetime.strptime(ap["end"], "%Y%m%dT%H%M%S")
|
||||||
|
|
||||||
if ap["end"] < now:
|
if end < now:
|
||||||
continue
|
continue
|
||||||
elif ap["begin"] > nextweek:
|
elif begin > nextweek:
|
||||||
continue
|
continue
|
||||||
elif len(application_periods) > 0 and application_periods[0]["begin"] + timedelta(hours=16) < ap["begin"]:
|
elif len(application_periods) > 0 and application_periods[0]["begin"] + timedelta(hours=16) < begin:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
application_periods.append(ap)
|
application_periods.append({"begin": begin, "end": end})
|
||||||
|
|
||||||
if ap["begin"] < yesterday:
|
if begin < yesterday:
|
||||||
oneline = True
|
oneline = True
|
||||||
|
|
||||||
if "cause" in disruption and disruption["cause"] == "travaux" and ap["begin"] > now:
|
if "cause" in disruption and disruption["cause"].lower() == "travaux" and begin > now:
|
||||||
oneline = True
|
oneline = True
|
||||||
|
|
||||||
if len(application_periods) == 0:
|
if len(application_periods) == 0:
|
||||||
@ -302,17 +313,11 @@ class RATPWeatherModule:
|
|||||||
elif application_periods[0]["end"] > now:
|
elif application_periods[0]["end"] > now:
|
||||||
subtitle = "Fin " + whenStr(application_periods[0]["end"], now)
|
subtitle = "Fin " + whenStr(application_periods[0]["end"], now)
|
||||||
|
|
||||||
for msg in disruption["messages"]:
|
id_seens.append(disruption["id"])
|
||||||
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 {
|
yield {
|
||||||
"title": title,
|
"title": disruption["title"],
|
||||||
"subtitle": subtitle,
|
"subtitle": subtitle,
|
||||||
"description": content,
|
"description": IDFMAPI.fromHTMLDisruption(disruption["message"]),
|
||||||
"icon": alert_icon(mode, line),
|
"icon": alert_icon(mode, line),
|
||||||
"oneline": oneline,
|
"oneline": oneline,
|
||||||
}
|
}
|
||||||
@ -342,13 +347,27 @@ class RATPWeatherModule:
|
|||||||
|
|
||||||
states = []
|
states = []
|
||||||
for disruption in weather[mode][line]:
|
for disruption in weather[mode][line]:
|
||||||
if disruption["status"] != "active":
|
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":
|
||||||
continue
|
continue
|
||||||
if "severity" in disruption:
|
if "severity" in disruption:
|
||||||
if disruption["cause"] == "travaux" and "line" not in [x["pt_object"]["embedded_type"] for x in disruption["impacted_objects"]]:
|
if disruption["cause"] == "TRAVAUX":
|
||||||
states.append(disruption["severity"]["effect"] + " " + disruption["cause"])
|
states.append(disruption["severity"] + " " + disruption["cause"])
|
||||||
else:
|
else:
|
||||||
states.append(disruption["severity"]["effect"])
|
states.append(disruption["severity"])
|
||||||
|
|
||||||
fill = "darkgray"
|
fill = "darkgray"
|
||||||
if "NO_SERVICE" in states:
|
if "NO_SERVICE" in states:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user