mirror of
https://github.com/mlesniew/elicznik.git
synced 2025-12-21 21:33:13 +01:00
Make get_readings return a list of namedtuples
This commit is contained in:
@@ -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))
|
readings = m.get_readings(datetime.date(2021, 7, 1), datetime.date(2021, 7, 31))
|
||||||
|
|
||||||
for timestamp, consumed, produced in readings:
|
for timestamp, consumed, produced, consumed_net, produced_net in readings:
|
||||||
print(timestamp, consumed, produced)
|
print(timestamp, consumed, produced, consumed_net, produced_net)
|
||||||
|
|
||||||
# single day
|
# single day
|
||||||
print("Yesterday")
|
print("Yesterday")
|
||||||
@@ -113,8 +113,8 @@ with elicznik.ELicznik("freddy@example.com", "secretpassword", "optional_site_id
|
|||||||
yesterday = datetime.date.today() - datetime.timedelta(days=1)
|
yesterday = datetime.date.today() - datetime.timedelta(days=1)
|
||||||
readings = m.get_readings(yesterday)
|
readings = m.get_readings(yesterday)
|
||||||
|
|
||||||
for timestamp, consumed, produced in readings:
|
for timestamp, consumed, produced, consumed_net, produced_net in readings:
|
||||||
print(timestamp, consumed, produced)
|
print(timestamp, consumed, produced, consumed_net, produced_net)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ def main():
|
|||||||
result,
|
result,
|
||||||
headers=[
|
headers=[
|
||||||
"timestamp",
|
"timestamp",
|
||||||
"consumed",
|
"consumption",
|
||||||
"produced",
|
"production",
|
||||||
"net consumption",
|
"net consumption",
|
||||||
"net production",
|
"net production",
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import collections
|
||||||
import csv
|
import csv
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from .session import Session
|
from .session import Session
|
||||||
|
|
||||||
|
|
||||||
|
Reading = collections.namedtuple("Reading", "timestamp consumption production net_consumption net_production")
|
||||||
|
|
||||||
|
|
||||||
class ELicznikBase:
|
class ELicznikBase:
|
||||||
LOGIN_URL = "https://logowanie.tauron-dystrybucja.pl/login"
|
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
|
# This probably drops the data from the double hour during DST change
|
||||||
# Needs to be investigated and fixed
|
# Needs to be investigated and fixed
|
||||||
return sorted(
|
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
|
for timestamp in timestamps
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -156,9 +160,9 @@ class ELicznikCSV(ELicznikBase):
|
|||||||
# This probably drops the data from the double hour during DST change
|
# This probably drops the data from the double hour during DST change
|
||||||
# Needs to be investigated and fixed
|
# Needs to be investigated and fixed
|
||||||
return sorted(
|
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
|
for timestamp in timestamps
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
ELicznik = ELicznikCSV
|
ELicznik = ELicznikCSV
|
||||||
|
|||||||
Reference in New Issue
Block a user