File: test_client.py

package info (click to toggle)
python-aioridwell 2024.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 1,062; sh: 41; makefile: 5
file content (44 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download
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
"""Run an example script to quickly test."""
import asyncio
import logging

from aiohttp import ClientSession

from aioridwell import async_get_client
from aioridwell.errors import RidwellError

_LOGGER = logging.getLogger()

EMAIL = "<EMAIL>"
PASSWORD = "<PASSWORD>"  # noqa: S105


async def main() -> None:
    """Create the aiohttp session and run the example."""
    logging.basicConfig(level=logging.INFO)
    async with ClientSession() as session:
        try:
            client = await async_get_client(EMAIL, PASSWORD, session=session)
            _LOGGER.info("User ID: %s", client.user_id)

            accounts = await client.async_get_accounts()
            _LOGGER.info("Accounts: %s", accounts)

            for account in accounts.values():
                events = await account.async_get_pickup_events()
                _LOGGER.info("Events for account ID %s: %s", account.account_id, events)

                first_event = events[0]
                estimated_addon_cost = (
                    await first_event.async_get_estimated_addon_cost()
                )
                _LOGGER.info(
                    "Estimated add-on cost for event %s: %s",
                    first_event.event_id,
                    estimated_addon_cost,
                )
        except RidwellError as err:
            _LOGGER.error("There was an error: %s", err)


asyncio.run(main())