ratp: Add message to disruptions
This commit is contained in:
parent
4bf17e2e39
commit
2bd7fafaa5
@ -3,6 +3,7 @@ import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
@ -64,7 +65,9 @@ class IDFMAPI:
|
||||
self.cache_timeout = config.cache_timeout
|
||||
self.max_cache_timeout = config.max_cache_timeout
|
||||
|
||||
def fromIVtoPRIM(src):
|
||||
def fromIVtoPRIM(src, line):
|
||||
cleanr = re.compile('<.*?>')
|
||||
cleanrA = re.compile('<a.*?>.*?</a>')
|
||||
return {
|
||||
"InfoChannelRef": {
|
||||
"value": "Perturbation" if src["severity"] >= 2 else "Travaux",
|
||||
@ -73,7 +76,9 @@ class IDFMAPI:
|
||||
"Message": [{
|
||||
"MessageType": "SHORT_MESSAGE",
|
||||
"MessageText": {
|
||||
"value": src["title"],
|
||||
"id": src["id"],
|
||||
"title": src["title"].replace("Métro " + line + " : ", '').replace("Ligne " + line + " : ", ''),
|
||||
"value": re.sub(cleanr, '', re.sub(cleanrA, '', src["message"].replace(' ', ' ').replace('’', "'").replace('à', 'à').replace('é', 'é').replace('è', 'è').replace('<br>', ' ').replace('</p>', ' ').replace('Information Ile de France Mobilités :', ''))).strip(),
|
||||
}
|
||||
}],
|
||||
}
|
||||
@ -167,7 +172,7 @@ class IDFMAPI:
|
||||
if "id" in l:
|
||||
if l["id"] == "line:IDFM:" + IDFMAPI.lines[mode][line]:
|
||||
for d in l["disruptions"]:
|
||||
yield IDFMAPI.fromIVtoPRIM(d)
|
||||
yield IDFMAPI.fromIVtoPRIM(d, line)
|
||||
|
||||
return None
|
||||
|
||||
@ -204,6 +209,7 @@ class RATPWeatherModule:
|
||||
alerts = []
|
||||
|
||||
weather = IDFMAPI(config).get_weather()
|
||||
id_seens = []
|
||||
for mode in weather:
|
||||
for line in weather[mode]:
|
||||
if mode[0].upper() + line not in self.major_lines:
|
||||
@ -224,7 +230,7 @@ class RATPWeatherModule:
|
||||
return icon
|
||||
|
||||
for info in weather[mode][line]:
|
||||
if "InfoChannelRef" not in info or info["InfoChannelRef"]["value"] != "Perturbation":
|
||||
if "InfoChannelRef" not in info or (info["InfoChannelRef"]["value"] != "Perturbation" and info["InfoChannelRef"]["value"] != "Travaux"):
|
||||
continue
|
||||
|
||||
if "Message" not in info["Content"]:
|
||||
@ -234,7 +240,12 @@ class RATPWeatherModule:
|
||||
if "MessageType" not in msg or msg["MessageType"] != "SHORT_MESSAGE":
|
||||
continue
|
||||
|
||||
if "id" in msg["MessageText"]:
|
||||
if msg["MessageText"]["id"] in id_seens:
|
||||
continue
|
||||
id_seens.append(msg["MessageText"]["id"])
|
||||
yield {
|
||||
"title": msg["MessageText"]["title"] if "title" in msg["MessageText"] else "",
|
||||
"description": msg["MessageText"]["value"].replace(" ", " "),
|
||||
"icon": alert_icon(mode, line),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user