Pegelonline/pomodules/pocurrentw.py
2025-09-27 12:54:39 +02:00

48 lines
1.9 KiB
Python

from . import poBaseURL
from .urlreader import UrlReader
class PoCurrentW(object):
def __init__(self):
self.url = poBaseURL + 'stations.json?timeseries=W&includeTimeseries=true&includeCurrentMeasurement=true'
def getCurrentW(self):
print("getCurrentW: Getting data...")
reader = UrlReader(self.url)
stations_json = reader.getJsonResponse()
if stations_json is None:
print("getCurrentW: FEHLER: Keine Stationen erhalten")
return None
print("getCurrentW: %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("getCurrentW: WARN: 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'],
'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("getCurrentW: %d / %d Stationen überführt" % (len(stations), len(stations_json)))
return stations