File: example.py

package info (click to toggle)
pytraccar 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 456 kB
  • sloc: python: 786; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 1,003 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
"""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),
            token=os.environ["TRACCAR_TOKEN"],
            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())