diff --git a/setup.py b/setup.py index 8d3632a..80fc267 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = (here / 'README.md').read_text(encoding='utf-8') setup( name='elicznik', - version='1.3.1', + version='1.4.0', description='Tauron eLicznik scrapper', long_description=long_description, long_description_content_type='text/markdown', diff --git a/src/elicznik/elicznik.py b/src/elicznik/elicznik.py index bcd73f7..5017063 100755 --- a/src/elicznik/elicznik.py +++ b/src/elicznik/elicznik.py @@ -32,28 +32,24 @@ class ELicznik: def __exit__(self, exc_type, exc_val, exc_tb): pass - def _get_raw_readings(self, type_, start_date, end_date=None): - end_date = end_date or start_date + def _get_raw_daily_readings(self, type_, date): data = self.session.post( self.CHART_URL, data={ "type": type_, - "from": start_date.strftime("%d.%m.%Y"), - "to": end_date.strftime("%d.%m.%Y"), + "from": date.strftime("%d.%m.%Y"), + "to": date.strftime("%d.%m.%Y"), "profile": "full time", }, - ).json() + ).json().get("data", {}).get("values", []) - data = data.get("data", {}).get("allData", {}) - for element in data: - date = element.get("Date") - hour = int(element.get("Hour")) - # TODO: There's also an "Extra" field, which seems to be set to be set to "T" only for the one extra hour - # when switching from CEST to CET (e.g. 3 AM on 2021-10-31) - timestamp = datetime.datetime.strptime(date, "%Y-%m-%d") - timestamp += datetime.timedelta(hours=hour) - value = element.get("EC") - yield timestamp, value + return ((datetime.datetime.combine(date, datetime.time(h)), value) for h, value in enumerate(data)) + + def _get_raw_readings(self, type_, start_date, end_date=None): + end_date = end_date or start_date + while start_date <= end_date: + yield from self._get_raw_daily_readings(type_, start_date) + start_date += datetime.timedelta(days=1) def get_readings_production(self, start_date, end_date=None): return dict(self._get_raw_readings("oze", start_date, end_date))