Deltares / ddlpy

API to Dutch Rijkswaterstaat archive (DDL, waterinfo.rws.nl) of monitoring water data
https://deltares.github.io/ddlpy/
GNU General Public License v3.0
20 stars 6 forks source link

add function for latest measurements #34

Closed veenstrajelmer closed 8 months ago

veenstrajelmer commented 8 months ago

Description

The option to retrieve the latest measurements from the webwaterservices is not exposed in ddlpy.

What I Did

import requests
import pandas as pd

# get laatste waarnemingen
url_ddl = 'https://waterwebservices.rijkswaterstaat.nl/ONLINEWAARNEMINGENSERVICES_DBO/OphalenLaatsteWaarnemingen'
request_ddl = {"AquoPlusWaarnemingMetadataLijst":[{"AquoMetadata":{"Compartiment":{"Code":"OW"},"Eenheid":{"Code":"cm"},
    "Grootheid":{"Code":"WATHTE"},
    "Hoedanigheid":{"Code":"NAP"},
    }}],
    "LocatieLijst":[{"X":518882.333320247,"Y":5760829.11729589,"Code":"EURPFM"
    }]
}
resp = requests.post(url_ddl, json=request_ddl)
if not resp.ok:
    raise Exception('%s for %s: %s'%(resp.reason, resp.url, str(resp.text)))
result = resp.json()
if not result['Succesvol']:
    raise Exception('query not succesful, Foutmelding: %s from %s'%(result['Foutmelding'],url_ddl))
for one in result['WaarnemingenLijst']:
    print(one['AquoMetadata']['Grootheid'])
    print(one['AquoMetadata']['Hoedanigheid'])
    print(one['AquoMetadata']['Groepering'])
    # print(one['MetingenLijst'])
    print(one['MetingenLijst'][0]['Tijdstip'])