oebb_py/workers/val.py

41 lines
1.1 KiB
Python

import json
import urllib.parse
from classes import *
def getValidator(name):
data = HTTPClient().get("http://scotty.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=255&REQ0JourneyStopsB=12&S=%s?&js=true&" % urllib.parse.quote(name)).text
return "=".join(data.split("=")[1:]).split(";")[0]
def validateName(name):
stations = json.loads(getValidator(name))
for station in stations["suggestions"]:
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)
def worker(name, json = False):
outtext = """{
"stations": [
""" if json else """<?xml version="1.0" encoding="UTF-8"?>
<stations>
"""
for station in validateName(name):
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 ""
outtext += """
]
}""" if json else "</stations>"
return outtext