#!/usr/bin/env python | |
from xml.etree import ElementTree | |
import requests | |
import json | |
import sys | |
import urllib | |
site = sys.argv[1] # e.g.'Seatoun Beach at Inglis Street', | |
if (len(sys.argv) > 2): | |
key = sys.argv[2] | |
else: | |
key = None | |
url = "http://hilltop.gw.govt.nz/Data.hts" | |
params = { | |
'Service': 'Hilltop', | |
'Request': 'GetData', | |
'Site': site, | |
'Measurement': 'Enterococci Bacteria' | |
} | |
# WRC's site only accepts the old %20 style of encoding | |
params = urllib.parse.urlencode(params, quote_via=urllib.parse.quote) | |
response = requests.get(url, params=params) | |
tree = ElementTree.fromstring(response.content) | |
reading = tree.find('Measurement').find('Data').find('E') | |
data = {'Enterococci': reading.find('Value').text} | |
for p in reading.findall("Parameter"): | |
data[p.attrib['Name']] = p.attrib['Value'] | |
if key: | |
print(data.get(key)) | |
else: | |
print(json.dumps(data)) |
This comment has been minimized.
This comment has been minimized.
sample home assistant config:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
sample output:
Note that the Enterococci never gets to zero, and instead says
<4
. e.g.{ "Enterococci": "<4"}