-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.py
40 lines (32 loc) · 1.04 KB
/
example.py
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
"""Example usage of pytraccar."""
import asyncio
import logging
import os
import aiohttp
from pytraccar import ApiClient
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[logging.StreamHandler()],
)
async def test() -> None:
"""Example usage of pytraccar."""
async with aiohttp.ClientSession(
cookie_jar=aiohttp.CookieJar(unsafe=True)
) as client_session:
client = ApiClient(
host=os.environ["TRACCAR_HOST"],
port=os.environ.get("TRACCAR_PORT", 8082),
username=os.environ["TRACCAR_USERNAME"],
password=os.environ["TRACCAR_PASSWORD"],
client_session=client_session,
)
server = await client.get_server()
logging.info(
"Connected to Traccar server (%s:%s) which is running version %s",
os.environ["TRACCAR_HOST"],
os.environ.get("TRACCAR_PORT", 8082),
server["version"],
)
asyncio.run(test())