47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from . import poBaseURL
|
|
from .urlreader import UrlReader
|
|
|
|
|
|
class PoStations(object):
|
|
|
|
def __init__(self):
|
|
self.url = poBaseURL + 'stations.json'
|
|
|
|
def getStations(self):
|
|
print("getStations: Getting data...")
|
|
|
|
reader = UrlReader(self.url)
|
|
stations_json = reader.getJsonResponse()
|
|
if stations_json is None:
|
|
print("getStations: Keine Stationen erhalten")
|
|
return None
|
|
|
|
print("getStations: %d Stationen erhalten" % (len(stations_json),))
|
|
|
|
stations = []
|
|
for station_json in stations_json:
|
|
if 'longitude' not in station_json or 'latitude' not in station_json or 'km' not in station_json:
|
|
print("getStations: Station hat fehlende Attribute: %s" % (station_json['longname'],))
|
|
continue
|
|
|
|
stations.append(
|
|
{
|
|
'geometry': {
|
|
'longitude':station_json['longitude'],
|
|
'latitude':station_json['latitude'],
|
|
},
|
|
'attributes': {
|
|
'uuid': station_json['uuid'],
|
|
'number': station_json['number'],
|
|
'shortname': station_json['shortname'],
|
|
'longname': station_json['longname'],
|
|
'km': station_json['km'],
|
|
'agency': station_json['agency'],
|
|
'water': station_json['water']['longname'],
|
|
},
|
|
}
|
|
)
|
|
|
|
print("getStations: %d / %d Stationen überführt" % (len(stations), len(stations_json)))
|
|
return stations
|