pax_global_header00006660000000000000000000000064136051640610014514gustar00rootroot0000000000000052 comment=11c81d79fc00a658d45367d85d166e6eebeb0363 fwestenberg-stookalert-11c81d7/000077500000000000000000000000001360516406100165465ustar00rootroot00000000000000fwestenberg-stookalert-11c81d7/LICENSE000066400000000000000000000020541360516406100175540ustar00rootroot00000000000000MIT 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/MANIFEST000066400000000000000000000001631360516406100176770ustar00rootroot00000000000000# file GENERATED by distutils, do NOT edit setup.cfg setup.py stookalert/__init__.py stookalert/rivm_stookalert.py fwestenberg-stookalert-11c81d7/README.md000066400000000000000000000012611360516406100200250ustar00rootroot00000000000000

Stookalert

This is a Python package for the RIVM Stookalert. Using the data supplied by this website.

Installation

Stookalert requires Python 3.6+ to run.

pip install stookalert
fwestenberg-stookalert-11c81d7/setup.cfg000066400000000000000000000000501360516406100203620ustar00rootroot00000000000000[metadata] description-file = README.md fwestenberg-stookalert-11c81d7/setup.py000066400000000000000000000013561360516406100202650ustar00rootroot00000000000000from 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/000077500000000000000000000000001360516406100207355ustar00rootroot00000000000000fwestenberg-stookalert-11c81d7/stookalert/__init__.py000066400000000000000000000000631360516406100230450ustar00rootroot00000000000000from stookalert.rivm_stookalert import stookalert fwestenberg-stookalert-11c81d7/stookalert/rivm_stookalert.py000066400000000000000000000035001360516406100245310ustar00rootroot00000000000000import 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"