Merge branch 'pythonModule'
This commit is contained in:
27
.drone.yml
Normal file
27
.drone.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: exec
|
||||||
|
name: default
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
steps:
|
||||||
|
- name: Run unit test
|
||||||
|
environment:
|
||||||
|
PYTHONPATH: .
|
||||||
|
commands:
|
||||||
|
- python setup.py test
|
||||||
|
- name: Build package files
|
||||||
|
commands:
|
||||||
|
- python setup.py sdist
|
||||||
|
- name: Versie toevoegen aan download
|
||||||
|
environment:
|
||||||
|
DOWNLOADDIR: /usr/share/nginx/html/download/python/dd-api-oper
|
||||||
|
commands:
|
||||||
|
- mkdir -p "$${DOWNLOADDIR}"
|
||||||
|
- cd dist
|
||||||
|
- for f in *;do if [ -f "$${DOWNLOADDIR}/$${f}" ] ; then echo version error;exit 1;else cp "$${f}" "$${DOWNLOADDIR}";fi;done
|
||||||
|
- ls -l "$${DOWNLOADDIR}"
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- master
|
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,6 +1,4 @@
|
|||||||
nijenhofm.crt
|
*.swp
|
||||||
nijenhofm.key
|
__pycache__
|
||||||
test-ddapi-nijenhofm
|
dd_oper_api.egg-info
|
||||||
|
dist
|
||||||
__pycache__:
|
|
||||||
ddapioper.cpython-37.pyc
|
|
||||||
|
@@ -24,6 +24,8 @@ inclusief:
|
|||||||
|
|
||||||
## De inhoud van de git repository
|
## De inhoud van de git repository
|
||||||
|
|
||||||
|
TODO: Aanpassen aan module
|
||||||
|
|
||||||
* ddapioper.py: Python module
|
* ddapioper.py: Python module
|
||||||
* test-ddapi: Een klein voorbeeld en test programma voor de module
|
* test-ddapi: Een klein voorbeeld en test programma voor de module
|
||||||
* DD-API-Oper demo.ipynb: Een [Jupyter notebook](met een demo).
|
* DD-API-Oper demo.ipynb: Een [Jupyter notebook](met een demo).
|
||||||
@@ -73,4 +75,4 @@ stabiele code!
|
|||||||
|
|
||||||
## Vragen en/of uitbreidingen.
|
## Vragen en/of uitbreidingen.
|
||||||
|
|
||||||
Vragen en of uitbreidingen kunnen gemaild worden naar ddapioper@pion.xs4all.nl.
|
Vragen en of uitbreidingen kunnen gemaild worden naar ddoperapi@pion.xs4all.nl.
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
This module contains the following classes:
|
This module contains the following classes:
|
||||||
|
|
||||||
* ddApiOper: Main class to connect to the dd api oper interface
|
* ddOperApi: Main class to connect to the dd api oper interface
|
||||||
* ddApiResult: Super class for results
|
* ddOperResult: Super class for results
|
||||||
- ddApiLocation: Result class for locations
|
- ddOperLocation: Result class for locations
|
||||||
- ddApiQuantitie: Result class for quantities
|
- ddOperQuantitie: Result class for quantities
|
||||||
- ddApiValues: Result class for values
|
- ddOperValues: Result class for values
|
||||||
* ddApiOperHttpError: Exception class for http errors
|
* ddOperApiHttpError: Exception class for http errors
|
||||||
|
|
||||||
See:
|
See:
|
||||||
https://digitaledeltaorg.github.io/dd-oper.v201.html
|
https://digitaledeltaorg.github.io/dd-oper.v201.html
|
||||||
@@ -19,7 +19,10 @@ import numpy as np
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from dateutil.parser import isoparse
|
from dateutil.parser import isoparse
|
||||||
|
|
||||||
class ddApiOper:
|
""" Version info changed by git hook """
|
||||||
|
__version__ = 'XXXX'
|
||||||
|
|
||||||
|
class ddOperApi:
|
||||||
"""
|
"""
|
||||||
Class that connects to the digitale delta api with a client certificate.
|
Class that connects to the digitale delta api with a client certificate.
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ class ddApiOper:
|
|||||||
RWS_DD_API = "https://ddapi.rws.nl/dd-oper/2.0"
|
RWS_DD_API = "https://ddapi.rws.nl/dd-oper/2.0"
|
||||||
|
|
||||||
def __init__(self, certfile=None, certkey=None, url=RWS_DD_API, checkssl=True):
|
def __init__(self, certfile=None, certkey=None, url=RWS_DD_API, checkssl=True):
|
||||||
"""ddApiOper(certfile, certKey, url="https://ddapi.rws.nl/dd-oper/2.0", checkssl=True)
|
"""ddOperApi(certfile, certKey, url="https://ddapi.rws.nl/dd-oper/2.0", checkssl=True)
|
||||||
|
|
||||||
certfile: x509 pki overheidscertificaat
|
certfile: x509 pki overheidscertificaat
|
||||||
certKey: Unencrypted private key
|
certKey: Unencrypted private key
|
||||||
@@ -48,7 +51,7 @@ Details for the certificate files see:
|
|||||||
self.certkey = certkey
|
self.certkey = certkey
|
||||||
self.url = url
|
self.url = url
|
||||||
self.checkssl = checkssl
|
self.checkssl = checkssl
|
||||||
logging.debug("ddApiOper.__init__(%s)" % url)
|
logging.debug("ddOperApi.__init__(%s)" % url)
|
||||||
|
|
||||||
def get(self, url):
|
def get(self, url):
|
||||||
"""get(url)
|
"""get(url)
|
||||||
@@ -57,29 +60,29 @@ Get the json data from the dd-api with pyton request.
|
|||||||
|
|
||||||
Note: Internal use!
|
Note: Internal use!
|
||||||
"""
|
"""
|
||||||
logging.debug("ddApiOper.get(%s)" % url)
|
logging.debug("ddOperApi.get(%s)" % url)
|
||||||
try:
|
try:
|
||||||
req = requests.get(url, cert=(self.certfile, self.certkey))
|
req = requests.get(url, cert=(self.certfile, self.certkey))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception("ddApiOper.get error: %s" % e)
|
logging.exception("ddOperApi.get error: %s" % e)
|
||||||
raise(e)
|
raise(e)
|
||||||
if (req.status_code != 200):
|
if (req.status_code != 200):
|
||||||
raise ddApiOperHttpError(req.status_code)
|
raise ddOperApiHttpError(req.status_code)
|
||||||
return(req.json())
|
return(req.json())
|
||||||
|
|
||||||
def locations(self):
|
def locations(self):
|
||||||
"""locations()
|
"""locations()
|
||||||
|
|
||||||
Request the list of locations and return a ddApiLocation object.
|
Request the list of locations and return a ddOperLocation object.
|
||||||
"""
|
"""
|
||||||
return(ddApiLocation(self.get(self.url + "/locations")["results"]))
|
return(ddOperLocation(self.get(self.url + "/locations")["results"]))
|
||||||
|
|
||||||
def quantities(self):
|
def quantities(self):
|
||||||
"""quantities()
|
"""quantities()
|
||||||
|
|
||||||
Request the list of quantities and return a ddApiQuntitie object.
|
Request the list of quantities and return a ddOperQuntitie object.
|
||||||
"""
|
"""
|
||||||
return(ddApiQuantitie(self.get(self.url + "/quantities")["results"]))
|
return(ddOperQuantitie(self.get(self.url + "/quantities")["results"]))
|
||||||
|
|
||||||
def locationQuantities(self, location):
|
def locationQuantities(self, location):
|
||||||
"""locationQuantities(location)
|
"""locationQuantities(location)
|
||||||
@@ -87,9 +90,9 @@ Request the list of quantities and return a ddApiQuntitie object.
|
|||||||
location: A dd-api location (e.g. hoekvanholland)
|
location: A dd-api location (e.g. hoekvanholland)
|
||||||
|
|
||||||
Request the list of quantities from a location and return
|
Request the list of quantities from a location and return
|
||||||
a ddApiQuntitie object.
|
a ddOperQuntitie object.
|
||||||
"""
|
"""
|
||||||
return(ddApiQuantitie(self.get(self.url + "/locations/%s/quantities" % location)["results"]))
|
return(ddOperQuantitie(self.get(self.url + "/locations/%s/quantities" % location)["results"]))
|
||||||
|
|
||||||
def values(self, location, quantitie, process="measurement",
|
def values(self, location, quantitie, process="measurement",
|
||||||
starttime=None, endtime=None,
|
starttime=None, endtime=None,
|
||||||
@@ -114,10 +117,10 @@ aspectset(optional): Default minimum (normal, maximum)
|
|||||||
starttime = starttime.isoformat() + "Z"
|
starttime = starttime.isoformat() + "Z"
|
||||||
if type(endtime) == datetime:
|
if type(endtime) == datetime:
|
||||||
endtime = endtime.isoformat() + "Z"
|
endtime = endtime.isoformat() + "Z"
|
||||||
logging.debug("ddApiOper.values(%s, %s, %s, %s, %s, %s, %s)" % (
|
logging.debug("ddOperApi.values(%s, %s, %s, %s, %s, %s, %s)" % (
|
||||||
location, quantitie, process, starttime, endtime,
|
location, quantitie, process, starttime, endtime,
|
||||||
intervalLength, aspectset))
|
intervalLength, aspectset))
|
||||||
return(ddApiValues(self.get((
|
return(ddOperValues(self.get((
|
||||||
"%s"
|
"%s"
|
||||||
"/locations/%s/quantities/%s"
|
"/locations/%s/quantities/%s"
|
||||||
"/timeseries?&startTime=%s&endTime=%s"
|
"/timeseries?&startTime=%s&endTime=%s"
|
||||||
@@ -131,22 +134,22 @@ aspectset(optional): Default minimum (normal, maximum)
|
|||||||
intervalLength, aspectset
|
intervalLength, aspectset
|
||||||
))))
|
))))
|
||||||
|
|
||||||
class ddApiResult(object):
|
class ddOperResult(object):
|
||||||
"""
|
"""
|
||||||
Class ddApiResult:
|
Class ddOperResult:
|
||||||
|
|
||||||
Base class for ddApiResults.
|
Base class for ddOperResults.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
"""ddApiResult(data)"""
|
"""ddOperResult(data)"""
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
class ddApiLocation(ddApiResult):
|
class ddOperLocation(ddOperResult):
|
||||||
"""
|
"""
|
||||||
Class ddApiLocation:
|
Class ddOperLocation:
|
||||||
|
|
||||||
ddApi Result class for locations.
|
ddOper Result class for locations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
@@ -192,11 +195,11 @@ Returns the coordinates of a location
|
|||||||
"""
|
"""
|
||||||
return(self.locationDetail(locationName)["geometry"]["coordinates"])
|
return(self.locationDetail(locationName)["geometry"]["coordinates"])
|
||||||
|
|
||||||
class ddApiQuantitie(ddApiResult):
|
class ddOperQuantitie(ddOperResult):
|
||||||
"""
|
"""
|
||||||
Class ddApiQuantitie:
|
Class ddOperQuantitie:
|
||||||
|
|
||||||
ddApi Result class for Quantities.
|
ddOper Result class for Quantities.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def quantities(self):
|
def quantities(self):
|
||||||
@@ -206,11 +209,11 @@ Returns a list of quantities
|
|||||||
"""
|
"""
|
||||||
return(self.data)
|
return(self.data)
|
||||||
|
|
||||||
class ddApiValues(ddApiResult):
|
class ddOperValues(ddOperResult):
|
||||||
"""
|
"""
|
||||||
Class ddApiValues:
|
Class ddOperValues:
|
||||||
|
|
||||||
ddApi Result class for values.
|
ddOper Result class for values.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def provider(self):
|
def provider(self):
|
||||||
@@ -330,9 +333,9 @@ Returns the result set as string in the sip format!
|
|||||||
sep = ";"
|
sep = ";"
|
||||||
return(r)
|
return(r)
|
||||||
|
|
||||||
class ddApiOperHttpError(Exception):
|
class ddOperApiHttpError(Exception):
|
||||||
"""
|
"""
|
||||||
Class ddApiOperHttpError
|
Class ddOperApiHttpError
|
||||||
|
|
||||||
Exception class to use on http errors.
|
Exception class to use on http errors.
|
||||||
"""
|
"""
|
||||||
@@ -342,9 +345,9 @@ Exception class to use on http errors.
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return("Code: %s" % self.code)
|
return("Code: %s" % self.code)
|
||||||
|
|
||||||
class ddApiOperJsonError(Exception):
|
class ddOperApiJsonError(Exception):
|
||||||
"""
|
"""
|
||||||
Class ddApiOperJsonError
|
Class ddOperApiJsonError
|
||||||
|
|
||||||
Exception class to use on json errors.
|
Exception class to use on json errors.
|
||||||
"""
|
"""
|
@@ -14,7 +14,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"## Een demo van de digitale delta api op basis van python\n",
|
"## Een demo van de digitale delta api op basis van python\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We zullen gebruik maken van de module \"ddapioper.py\" waarmee we het gebruik demonstreren. We starten met de import van de module.\n",
|
"We zullen gebruik maken van de module \"ddOperApi\" waarmee we het gebruik demonstreren. We starten met de import van de module.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Vervolgens maken we een object aan die we het certificaat mee geven. Dit object rws verzorgt de dd-api calls."
|
"Vervolgens maken we een object aan die we het certificaat mee geven. Dit object rws verzorgt de dd-api calls."
|
||||||
]
|
]
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from ddapioper import ddApiOper"
|
"from ddOperApi import ddOperApi"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
6
githooks/pre-commit
Executable file
6
githooks/pre-commit
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
VERSION=$(grep version setup.py | sed -e 's/.*="//' -e 's/",//')
|
||||||
|
sed -i "s/^__version__ = .*/__version__ = '${VERSION}'/" dd-oper-api/__init__.py
|
||||||
|
git add lmwsip/__init__.py
|
||||||
|
|
||||||
|
python setup.py test
|
26
setup.py
Normal file
26
setup.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
with open("README.md", "r") as fh:
|
||||||
|
long_description = fh.read()
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name="dd-oper-api", # Replace with your own username
|
||||||
|
version="0.0.1",
|
||||||
|
author="Marcel Nijenhof",
|
||||||
|
author_email="pip@pion.xs4all.nl",
|
||||||
|
description="Interface for dd-oper protocol",
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
url="https://marceln.org/git/Werk/lmwsip",
|
||||||
|
packages=setuptools.find_packages(),
|
||||||
|
install_requires=[
|
||||||
|
'python-dateutil',
|
||||||
|
],
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: TODO",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Topic :: dd-oper api"
|
||||||
|
],
|
||||||
|
python_requires='>=3.6',
|
||||||
|
)
|
10
test-ddapi
10
test-ddapi
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from ddapioper import ddApiOper
|
from ddOperApi import ddOperApi
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
def locations(rws):
|
def locations(rws):
|
||||||
@@ -34,10 +34,10 @@ def waterlevelHoekvanHolland(rws):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
rws = ddApiOper("<TODO>.crt", "<TODO>.key")
|
rws = ddOperApi("<TODO>.crt", "<TODO>.key")
|
||||||
#locations(rws)
|
locations(rws)
|
||||||
#quantities(rws)
|
quantities(rws)
|
||||||
#quantitiesHoekvanHolland(rws)
|
quantitiesHoekvanHolland(rws)
|
||||||
waterlevelHoekvanHolland(rws)
|
waterlevelHoekvanHolland(rws)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user