oebb_py/workers/val.py

35 lines
880 B
Python

import requests
import json
import urllib.parse
from classes import *
def getValidator(name):
return requests.get("http://www.oebb.at/__ressources/system/stationsHafas.jsp?q=%s" % name).text
def validateName(name):
stations = json.loads(getValidator(name))
for station in stations:
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):
outtext = """<?xml version="1.0" encoding="UTF-8"?>
<stations>
"""
for station in validateName(name):
outtext += "<station><name>%s</name><id>%s</id></station>\n" % (station.name, station.useId())
outtext += "</stations>"
return outtext