Add power/inferred tops filtering to nrtrains
This commit is contained in:
parent
69b1a6bd9b
commit
9d62e6f301
1 changed files with 19 additions and 3 deletions
|
@ -122,6 +122,10 @@ class Module(object):
|
||||||
client = self.client
|
client = self.client
|
||||||
colours = self.COLOURS
|
colours = self.COLOURS
|
||||||
|
|
||||||
|
eagle_key = self.bot.config["eagle-api-key"]
|
||||||
|
eagle_url = self.bot.config["eagle-api-url"]
|
||||||
|
schedule = {}
|
||||||
|
|
||||||
location_code = event["args_split"][0].upper()
|
location_code = event["args_split"][0].upper()
|
||||||
filter = self.filter(' '.join(event["args_split"][1:]) if len(event["args_split"]) > 1 else "", {
|
filter = self.filter(' '.join(event["args_split"][1:]) if len(event["args_split"]) > 1 else "", {
|
||||||
"dest": ('', lambda x: x.isalpha() and len(x)==3),
|
"dest": ('', lambda x: x.isalpha() and len(x)==3),
|
||||||
|
@ -132,7 +136,11 @@ class Module(object):
|
||||||
"plat": ('', lambda x: len(x) <= 3),
|
"plat": ('', lambda x: len(x) <= 3),
|
||||||
"type": ("departure", lambda x: x in ["departure", "arrival", "both"]),
|
"type": ("departure", lambda x: x in ["departure", "arrival", "both"]),
|
||||||
"terminating": (False, lambda x: type(x)==type(True)),
|
"terminating": (False, lambda x: type(x)==type(True)),
|
||||||
"period": (120, lambda x: x.isdigit() and 1 <= int(x) <= 240, lambda x: int(x))
|
"period": (120, lambda x: x.isdigit() and 1 <= int(x) <= 240, lambda x: int(x)),
|
||||||
|
"nonpassenger": (False, lambda x: type(x)==type(True)),
|
||||||
|
"timebase": ("0000", lambda x: len(x)==4 and x.isdigit()),
|
||||||
|
"tops": (None, lambda x: len(x)<4 and x.isdigit()),
|
||||||
|
"power": (None, lambda x: x.upper() in ["EMU", "DMU", "HST"], lambda x: x.upper()),
|
||||||
})
|
})
|
||||||
|
|
||||||
if filter["errors"]:
|
if filter["errors"]:
|
||||||
|
@ -147,7 +155,7 @@ class Module(object):
|
||||||
method = client.service.GetArrivalDepartureBoardByCRS if len(location_code) == 3 else client.service.GetArrivalDepartureBoardByTIPLOC
|
method = client.service.GetArrivalDepartureBoardByCRS if len(location_code) == 3 else client.service.GetArrivalDepartureBoardByTIPLOC
|
||||||
try:
|
try:
|
||||||
query = method(100, location_code, datetime.now().isoformat().split(".")[0], filter["period"],
|
query = method(100, location_code, datetime.now().isoformat().split(".")[0], filter["period"],
|
||||||
nr_filterlist, "to", '', "PBS", False)
|
nr_filterlist, "to", '', "PBS", filter["nonpassenger"])
|
||||||
except WebFault as detail:
|
except WebFault as detail:
|
||||||
if str(detail) == "Server raised fault: 'Invalid crs code supplied'":
|
if str(detail) == "Server raised fault: 'Invalid crs code supplied'":
|
||||||
return event["stderr"].write("Invalid CRS code.")
|
return event["stderr"].write("Invalid CRS code.")
|
||||||
|
@ -198,6 +206,12 @@ class Module(object):
|
||||||
|
|
||||||
trains.append(parsed)
|
trains.append(parsed)
|
||||||
|
|
||||||
|
if eagle_url:
|
||||||
|
summary_query = Utils.get_url("%s/summaries/%s?uids=%s" % (eagle_url, datetime.now().date().isoformat(), "%20".join([a["uid"] for a in trains])), json=True)
|
||||||
|
if summary_query:
|
||||||
|
for t in trains:
|
||||||
|
t.update(summary_query[t["uid"]])
|
||||||
|
|
||||||
for t in trains:
|
for t in trains:
|
||||||
t["dest_summary"] = "/".join(["%s%s" %(a["name"], " " + a["via"]
|
t["dest_summary"] = "/".join(["%s%s" %(a["name"], " " + a["via"]
|
||||||
if a["via"] else '') for a in t["destinations"]])
|
if a["via"] else '') for a in t["destinations"]])
|
||||||
|
@ -218,7 +232,9 @@ class Module(object):
|
||||||
filter["plat"] and not filter["plat"] == train["platform"],
|
filter["plat"] and not filter["plat"] == train["platform"],
|
||||||
filter["type"] == "departure" and train["terminating"],
|
filter["type"] == "departure" and train["terminating"],
|
||||||
filter["type"] == "arrival" and train["departure_only"],
|
filter["type"] == "arrival" and train["departure_only"],
|
||||||
filter["terminating"] and not train["terminating"]
|
filter["terminating"] and not train["terminating"],
|
||||||
|
filter["tops"] and not filter["tops"] in train.get("tops_possible", []),
|
||||||
|
filter["power"] and not filter["power"]==train.get("power_type", None),
|
||||||
]:
|
]:
|
||||||
train_locs_toc.append((train["destinations"], train["toc"]))
|
train_locs_toc.append((train["destinations"], train["toc"]))
|
||||||
trains_filtered.append(train)
|
trains_filtered.append(train)
|
||||||
|
|
Loading…
Reference in a new issue