42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
from . import poBaseURL
|
|
from .urlreader import UrlReader
|
|
|
|
|
|
class PoWaterlevels(UrlReader):
|
|
|
|
def __init__(self):
|
|
super().__init__(poBaseURL + 'stations.json?timeseries=W&includeTimeseries=true&includeCurrentMeasurement=true')
|
|
|
|
def getWaterlevels(self):
|
|
print("getWaterlevels: Lade Pegelstände herunter...")
|
|
|
|
stations_json = self.getJsonResponse()
|
|
if stations_json is None or len(stations_json) == 0:
|
|
print("getWaterlevels: FEHLER: Keine Pegelstände erhalten")
|
|
return None
|
|
|
|
stations = []
|
|
for station_json in stations_json:
|
|
stations.append(
|
|
{
|
|
'geometry': {
|
|
'longitude': station_json['longitude'] if 'longitude' in station_json else None,
|
|
'latitude': station_json['latitude'] if 'latitude' in station_json else None,
|
|
},
|
|
'attributes': {
|
|
'uuid': station_json['uuid'],
|
|
'shortname': station_json['shortname'],
|
|
'number': station_json['number'],
|
|
'agency': station_json['agency'],
|
|
'timestamp': station_json['timeseries'][0]['currentMeasurement']['timestamp'],
|
|
'value': station_json['timeseries'][0]['currentMeasurement']['value'],
|
|
'stateMnwMhw': station_json['timeseries'][0]['currentMeasurement']['stateMnwMhw'],
|
|
'stateNswHsw': station_json['timeseries'][0]['currentMeasurement']['stateNswHsw'],
|
|
},
|
|
}
|
|
)
|
|
|
|
print("getWaterlevels: %d Pegelstände erhalten" % (len(stations),))
|
|
|
|
return stations
|