oebb_py/workers/val.py

42 lines
1.1 KiB
Python
Raw Normal View History

2017-09-21 12:48:05 +00:00
import json
import urllib.parse
from classes import *
def getValidator(name):
2019-04-16 18:04:19 +00:00
data = HTTPClient().get("http://scotty.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=255&REQ0JourneyStopsB=12&S='%s'?&js=true&" % urllib.parse.quote(name.encode("latin-1"))).text
2019-03-14 09:46:39 +00:00
return "=".join(data.split("=")[1:]).split(";")[0]
2017-09-21 12:48:05 +00:00
def validateName(name):
stations = json.loads(getValidator(name))
2019-03-14 09:46:39 +00:00
for station in stations["suggestions"]:
2017-09-21 12:48:05 +00:00
name = station["value"]
sttype = station["type"]
try:
extid = station["extId"]
except:
extid = None
xcoord = station["xcoord"]
ycoord = station["ycoord"]
prodclass = station["prodClass"]
yield Station(name = name, sttype = sttype, extid = extid, xcoord = xcoord, ycoord = ycoord, prodclass = prodclass)
2017-09-23 14:57:24 +00:00
def worker(name, json = False):
2017-09-24 19:04:59 +00:00
outtext = """{
"stations": [
""" if json else """<?xml version="1.0" encoding="UTF-8"?>
2017-09-23 14:57:24 +00:00
<stations>
"""
for station in validateName(name):
2017-09-24 19:04:59 +00:00
outtext += ",\n" if (json and not outtext.strip()[-1] == "[") else ""
outtext += station.json(2) if json else station.xml(1)
outtext += "\n" if not json else ""
2017-09-24 19:04:59 +00:00
outtext += """
]
}""" if json else "</stations>"
return outtext