Skip to content

Commit

Permalink
Adjust example
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Feb 11, 2024
1 parent cb6fdd8 commit 45e2854
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,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():

async def test() -> None:
"""Example usage of pytraccar."""
async with aiohttp.ClientSession() as client_session:
async with aiohttp.ClientSession(
cookie_jar=aiohttp.CookieJar(unsafe=True)
) as client_session:
client = ApiClient(
host="127.0.0.1",
username="admin",
password="Password123!",
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,
)
print(await client.get_server())
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"],
)


LOOP = asyncio.get_event_loop()
LOOP.run_until_complete(test())
asyncio.run(test())

0 comments on commit 45e2854

Please sign in to comment.