Skip to content

Commit

Permalink
Make get_readings return a list of namedtuples
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesniew committed May 19, 2024
1 parent 7e5e2ed commit cd9ebcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ with elicznik.ELicznik("[email protected]", "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")
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)
```


Expand Down
4 changes: 2 additions & 2 deletions src/elicznik/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def main():
result,
headers=[
"timestamp",
"consumed",
"produced",
"consumption",
"production",
"net consumption",
"net production",
],
Expand Down
10 changes: 7 additions & 3 deletions src/elicznik/elicznik.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -85,7 +89,7 @@ def get_readings(self, start_date, end_date=None):
# 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
)

Expand Down Expand Up @@ -156,9 +160,9 @@ def get_readings(self, start_date, end_date=None):
# 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
ELicznik = ELicznikCSV

0 comments on commit cd9ebcf

Please sign in to comment.