From cd9ebcf9aaba437dcf4fb771fbb8e6a2d90e8725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Le=C5=9Bniewski?= Date: Sun, 19 May 2024 18:08:16 +0200 Subject: [PATCH] Make get_readings return a list of namedtuples --- README.md | 8 ++++---- src/elicznik/__main__.py | 4 ++-- src/elicznik/elicznik.py | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 87e297c..3fd4141 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,8 @@ with elicznik.ELicznik("freddy@example.com", "secretpassword", "optional_site_id readings = m.get_readings(datetime.date(2021, 7, 1), datetime.date(2021, 7, 31)) - for timestamp, consumed, produced in readings: - print(timestamp, consumed, produced) + for timestamp, consumed, produced, consumed_net, produced_net in readings: + print(timestamp, consumed, produced, consumed_net, produced_net) # single day print("Yesterday") @@ -113,8 +113,8 @@ with elicznik.ELicznik("freddy@example.com", "secretpassword", "optional_site_id yesterday = datetime.date.today() - datetime.timedelta(days=1) readings = m.get_readings(yesterday) - for timestamp, consumed, produced in readings: - print(timestamp, consumed, produced) + for timestamp, consumed, produced, consumed_net, produced_net in readings: + print(timestamp, consumed, produced, consumed_net, produced_net) ``` diff --git a/src/elicznik/__main__.py b/src/elicznik/__main__.py index ca704e7..4602b1b 100644 --- a/src/elicznik/__main__.py +++ b/src/elicznik/__main__.py @@ -71,8 +71,8 @@ def main(): result, headers=[ "timestamp", - "consumed", - "produced", + "consumption", + "production", "net consumption", "net production", ], diff --git a/src/elicznik/elicznik.py b/src/elicznik/elicznik.py index 696ee45..5683d88 100755 --- a/src/elicznik/elicznik.py +++ b/src/elicznik/elicznik.py @@ -1,11 +1,15 @@ #!/usr/bin/env python3 +import collections import csv import datetime from .session import Session +Reading = collections.namedtuple("Reading", "timestamp consumption production net_consumption net_production") + + class ELicznikBase: LOGIN_URL = "https://logowanie.tauron-dystrybucja.pl/login" @@ -85,7 +89,7 @@ class ELicznikChart(ELicznikBase): # This probably drops the data from the double hour during DST change # Needs to be investigated and fixed return sorted( - tuple([timestamp] + [results[name].get(timestamp) for name in COLUMNS]) + Reading(*([timestamp] + [results[name].get(timestamp) for name in COLUMNS])) for timestamp in timestamps ) @@ -156,9 +160,9 @@ class ELicznikCSV(ELicznikBase): # This probably drops the data from the double hour during DST change # Needs to be investigated and fixed return sorted( - tuple([timestamp] + [results[name].get(timestamp) for name in COLUMNS]) + Reading(*([timestamp] + [results[name].get(timestamp) for name in COLUMNS])) for timestamp in timestamps ) -ELicznik = ELicznikCSV \ No newline at end of file +ELicznik = ELicznikCSV