Fix JSON for connections

This commit is contained in:
Klaus-Uwe Mitterer 2017-10-11 14:31:10 +02:00
parent 337fe033c3
commit 269069878f
2 changed files with 12 additions and 3 deletions

View file

@ -71,7 +71,7 @@ class Connection:
out += self.depst().xml(indent + 2, **stationkwargs) + "\n"
out += " " * indent + " </from>\n"
if via and self.via != 0:
if via and self.via:
out += " " * indent + " <via>\n"
for vst in self.via:
@ -116,7 +116,7 @@ class Connection:
return out
def json(self, indent = 0, cid = False, frm = True, to = True, deptime = True, arrtime = True, duration = True, changes = True, services = True, servicekwargs = {}, stationkwargs = {}):
def json(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 + "{\n"
out += (" " * indent + " \"@id\": %i,\n" % cid) if cid is not False else ""
@ -125,6 +125,15 @@ class Connection:
out += " " * indent + " \"from\":\n"
out += self.depst().json(indent + 2, **stationkwargs) + ",\n"
if via and self.via:
out += " " * indent + " \"via\": [\n"
for vst in self.via:
out += vst.json(indent + 3, **stationkwargs) + ",\n"
out = "".join(out.rsplit(",", 1))
out += " " * indent + " ]\n"
if to:
out += " " * indent + " \"to\":\n"
out += self.arrst().json(indent + 2, **stationkwargs) + ",\n"

View file

@ -21,7 +21,7 @@ def getTrains(names = None):
if not find:
for cname in names:
if cname.lower().replace(" ", "") == name.split("-")[0].lower().replace(" ", ""):
if cname.lower().replace(" ", "") == name.split("-")[0].lower().replace(" ", "") or name.lower().replace(" ", "").startswith(cname.lower().replace(" ", "")):
find = True
if find: