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" % urllib.parse.quote(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, json = False): outtext = """{ "stations": [ """ if json else """ """ 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 "" return outtext