Blindly implement via routing. Needs testing before deployment,

This commit is contained in:
Klaus-Uwe Mitterer 2017-10-02 10:05:31 +02:00
parent e9a2d9ef43
commit a7a6305d54
3 changed files with 26 additions and 5 deletions

View file

@ -4,10 +4,14 @@ class Connection:
def __init__(self, details = False):
self.services = []
self.details = details
self.via = []
def addService(self, service):
self.services.append(service)
def addVia(self, station):
self.via.append(station)
def depst(self):
try:
return self.services[0].depst
@ -59,7 +63,7 @@ class Connection:
def changes(self):
return max(len([service for service in self.services if service.name != "Walk"]) - 1, 0) if self.details else max(len([service for service in self.services[0].name.split("/") if service != "Walk"]) - 1, 0)
def xml(self, indent = 0, cid = False, frm = True, to = True, deptime = True, arrtime = True, duration = True, changes = True, services = True, servicekwargs = {}, stationkwargs = {}):
def xml(self, indent = 0, cid = False, frm = True, to = True, deptime = True, arrtime = True, duration = True, changes = True, services = True, via = True servicekwargs = {}, stationkwargs = {}):
out = " " * indent + "<connection%s>\n" % ("" if cid is False else " id=\"%i\"" % cid)
if frm:
@ -67,6 +71,14 @@ class Connection:
out += self.depst().xml(indent + 2, **stationkwargs) + "\n"
out += " " * indent + " </from>\n"
if via and self.via:
out += " " * indent + " <via>\n"
for vst in self.via:
out += vst.xml(indent + 2, **stationkwargs) + "\n"
out += " " * indent + " </via>\n"
if to:
out += " " * indent + " <to>\n"
out += self.arrst().xml(indent + 2, **stationkwargs) + "\n"

View file

@ -93,8 +93,10 @@ def application(env, re):
yield "The \"date\" value must be in DD.MM.YYYY format, the \"time\" value must be in HH:MM format."
return
via = list(args["via"]) if "via" in args else None
try:
output = workers.conn.worker(frm, to, count, outtime, mode, details, json)
output = workers.conn.worker(frm, to, count, outtime, mode, details, json, via)
except Exception as e:
re("500 Internal Server Error", [])
yield "<h1>500 Internal Server Error</h1>".encode()

View file

@ -9,11 +9,15 @@ from classes import *
def getStation(name):
return list(workers.val.validateName(name))[0]
def connRequest(frm, to, count = 3, time = datetime.datetime.now(), mode = False, details = False):
def connRequest(frm, to, count = 3, time = datetime.datetime.now(), mode = False, details = False, via = []):
outdate = datetime.datetime.strftime(time,"%d.%m.%Y")
outtime = datetime.datetime.strftime(time,"%H:%M")
url = "http://fahrplan.oebb.at/bin/query.exe/dn?start=1&S=%s&Z=%s&REQ0JourneyDate=%s&time=%s&REQ0HafasNumCons0=%s%s" % (frm.extid if frm.extid else frm.name, to.extid if to.extid else to.name, outdate, outtime, count, "&timesel=arrive" if mode else "")
for i in range(len(via)):
url += "&REQ0JourneyStops%i.0G=%s&REQ0JourneyStops%i.0A=1" % (i + 1, via[i].extid if via[i].extid else via[i].name, i + 1)
source = requests.get(url).text
if "GO_conViewMode=outward" not in source:
@ -42,6 +46,9 @@ def connRequest(frm, to, count = 3, time = datetime.datetime.now(), mode = False
conn = Connection(details)
for vst in via:
conn.addVia(vst)
lines = cont.findAll("tr", { "class": "tpDetails" })[1:]
cdate = None
@ -125,8 +132,8 @@ def connRequest(frm, to, count = 3, time = datetime.datetime.now(), mode = False
yield con
def worker(frm, to, count = 3, time = datetime.datetime.now(pytz.timezone("Europe/Vienna")), mode = False, details = False, json = False):
conns = list(connRequest(getStation(frm), getStation(to), count, time, mode, details))
def worker(frm, to, count = 3, time = datetime.datetime.now(pytz.timezone("Europe/Vienna")), mode = False, details = False, json = False, via = None):
conns = list(connRequest(getStation(frm), getStation(to), count, time, mode, details, [getStation(vst) for vst in via]))
output = """<?xml version="1.0" encoding="UTF-8"?>
<connections>