-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathusage_example.py
More file actions
57 lines (44 loc) · 1.67 KB
/
usage_example.py
File metadata and controls
57 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Example of usage of the Veolia API with logging"""
import asyncio
import logging
from datetime import date
import aiohttp
from veolia_api.portals import VEOLIA_PORTAL_CLIENTS
from veolia_api.veolia_api import VeoliaAPI
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
)
logger = logging.getLogger("VeoliaExample")
async def main() -> None:
"""Main function with logging."""
logger.info("Starting Veolia API example script")
logger.info("Available portals: %s", list(VEOLIA_PORTAL_CLIENTS))
# Pick your portal — defaults to the first entry if omitted
# portal_url = "eau.veolia.fr"
portal_url = None
async with aiohttp.ClientSession() as session:
logger.debug("Creating VeoliaAPI client")
client_api = VeoliaAPI("email", "password", session, portal_url=portal_url)
start_date = date(2025, 1, 1)
end_date = date(2025, 9, 1)
logger.info(f"Fetching data from {start_date} to {end_date}")
try:
await client_api.fetch_all_data(start_date, end_date)
logger.info("Data fetch completed successfully")
except Exception as e:
logger.exception("Error while fetching data")
return
# Log consumption data
logger.info(
f"Daily consumption count: {len(client_api.account_data.daily_consumption)}"
)
logger.info(
f"Monthly consumption count: {len(client_api.account_data.monthly_consumption)}"
)
logger.info(
f"Daily alert enabled: {client_api.account_data.alert_settings.daily_enabled}"
)
logger.info("OK")
if __name__ == "__main__":
asyncio.run(main())