-
Notifications
You must be signed in to change notification settings - Fork 2
/
example-user.py
executable file
·34 lines (25 loc) · 1001 Bytes
/
example-user.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
#!/usr/bin/env python3
"""Example code for private charger."""
from asyncio import new_event_loop
from logging import DEBUG, basicConfig, error, info
from os import getenv
from sys import stdout
from aiohttp import ClientSession
from shellrecharge import Api
from shellrecharge.user import LoginFailedError
async def main():
async with ClientSession() as session:
try:
api = Api(session)
usr = await api.get_user(getenv("SHELL_USER"), getenv("SHELL_PWD"))
cards = [card async for card in usr.get_cards()]
chargers = [charger async for charger in usr.get_chargers()]
info(cards[0])
info(chargers[0])
await usr.toggle_charger(chargers[0]["id"], cards[0]["rfid"], "start")
except LoginFailedError:
error("Login failed, check your credentials")
if __name__ == "__main__":
basicConfig(stream=stdout, level=DEBUG)
loop = new_event_loop()
loop.run_until_complete(main())