pax_global_header 0000666 0000000 0000000 00000000064 13605164061 0014514 g ustar 00root root 0000000 0000000 52 comment=11c81d79fc00a658d45367d85d166e6eebeb0363 fwestenberg-stookalert-11c81d7/ 0000775 0000000 0000000 00000000000 13605164061 0016546 5 ustar 00root root 0000000 0000000 fwestenberg-stookalert-11c81d7/LICENSE 0000664 0000000 0000000 00000002054 13605164061 0017554 0 ustar 00root root 0000000 0000000 MIT License Copyright (c) 2019 fwestenberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fwestenberg-stookalert-11c81d7/MANIFEST 0000664 0000000 0000000 00000000163 13605164061 0017677 0 ustar 00root root 0000000 0000000 # file GENERATED by distutils, do NOT edit setup.cfg setup.py stookalert/__init__.py stookalert/rivm_stookalert.py fwestenberg-stookalert-11c81d7/README.md 0000664 0000000 0000000 00000001261 13605164061 0020025 0 ustar 00root root 0000000 0000000
This is a Python package for the RIVM Stookalert. Using the data supplied by this website.
Stookalert requires Python 3.6+ to run.
pip install stookalert
fwestenberg-stookalert-11c81d7/setup.cfg 0000664 0000000 0000000 00000000050 13605164061 0020362 0 ustar 00root root 0000000 0000000 [metadata]
description-file = README.md
fwestenberg-stookalert-11c81d7/setup.py 0000664 0000000 0000000 00000001356 13605164061 0020265 0 ustar 00root root 0000000 0000000 from distutils.core import setup
setup(
name = 'stookalert',
packages = ['stookalert'],
version = '0.1.4',
license='MIT',
description = 'Stookalert package',
author = 'fwestenberg',
author_email = '',
url = 'https://github.com/fwestenberg/stookalert',
download_url = 'https://github.com/fwestenberg/stookalert/archive/v_014.tar.gz',
keywords = ['Stookalert', 'Home-Assistant'],
install_requires=[
'requests',
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
],
)
fwestenberg-stookalert-11c81d7/stookalert/ 0000775 0000000 0000000 00000000000 13605164061 0020735 5 ustar 00root root 0000000 0000000 fwestenberg-stookalert-11c81d7/stookalert/__init__.py 0000664 0000000 0000000 00000000063 13605164061 0023045 0 ustar 00root root 0000000 0000000 from stookalert.rivm_stookalert import stookalert
fwestenberg-stookalert-11c81d7/stookalert/rivm_stookalert.py 0000664 0000000 0000000 00000003500 13605164061 0024531 0 ustar 00root root 0000000 0000000 import json
import logging
from datetime import datetime, timedelta
import requests
UPDATEHOUR = 12
RESETHOUR = 3
NAME = "naam"
VALUE = "waarde"
_LOGGER = logging.getLogger(__name__)
class stookalert(object):
def __init__(self, province):
self._state = None
self._alerts = {}
self._province = province.lower()
self._last_updated = None
if self._province is not None:
_LOGGER.info(f"Setting up Stookalert for province {province}")
else:
_LOGGER.info("Please provide a province name")
@property
def state(self):
return self._state
@property
def last_updated(self):
return self._last_updated
def get_alerts(self):
alerts = self.request()
if alerts is None:
return
for a in alerts:
province = a.get(NAME, "").lower()
value = a.get(VALUE, None)
self._alerts[province] = value
if province == self._province:
self._state = value
def request(self):
try:
response = requests.get(self.get_url(), timeout=10)
self._last_updated = datetime.now()
json_response = json.loads(response.text)
return sorted(json_response, key = lambda i: i[NAME])
except requests.exceptions.RequestException:
_LOGGER.error("Error getting Stookalert data")
def get_url(self):
updateDay = datetime.now()
if updateDay.hour < RESETHOUR:
updateDay = updateDay - timedelta(days=1)
elif updateDay.hour < UPDATEHOUR:
return f"https://www.rivm.nl/media/lml/stookalert/stookalert_noalert.json"
return f"https://www.rivm.nl/media/lml/stookalert/stookalert_{updateDay.strftime('%Y%m%d')}.json"