Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import requests
- from collections import namedtuple
- from lxml import etree
- import csv
- import sys
- Bbox = namedtuple('Bbox', ['x_min', 'y_min', 'x_max', 'y_max'])
- bbox = Bbox(
- x_min = '566732.5126428431',
- x_max = '566866.1271540247',
- y_min = '5934895.9206352',
- y_max = '5935029.535146381'
- )
- url = 'https://geoportal-hamburg.de/geodienste_hamburg_de/HH_WMS_Radverkehrszaehlsaeulen'
- params = {
- 'SERVICE': 'WMS',
- 'VERSION': '1.3.0',
- 'REQUEST': 'GetFeatureInfo',
- 'LAYERS': ','.join(['zaehlstellen']),
- 'QUERY_LAYERS': ','.join(['zaehlstellen']),
- 'STYLES': ','.join([]),
- 'CRS': 'EPSG:25832',
- 'BBOX': ','.join(bbox),
- 'WIDTH': 101,
- 'HEIGHT': 101,
- 'FORMAT': 'image/png',
- 'INFO_FORMAT': 'text/xml',
- 'FEATURE_COUNT': '1',
- 'I': '50',
- 'J': '50',
- }
- nsmap = {
- 'app': 'http://www.deegree.org/app',
- }
- resp = etree.fromstring(requests.get(url, params=params).content)
- writer = csv.DictWriter(sys.stdout, ['Messstelle', 'Tag', 'Zeit', 'Anzahl'])
- writer.writeheader()
- for zs in resp.xpath('//app:zaehlsaeulen', namespaces=nsmap):
- name = zs.xpath('app:name/text()', namespaces=nsmap)[0]
- tageslinie = zs.xpath('app:tageslinie/text()', namespaces=nsmap)[0]
- for messung in tageslinie.split('|'):
- tag, zeit, anzahl = messung.split(',')
- writer.writerow({
- 'Messstelle': name,
- 'Tag': tag,
- 'Zeit': zeit,
- 'Anzahl': anzahl,
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement