generated from Justintime50/python-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
54 lines (48 loc) · 2.08 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
import asyncio
from pynintendoparental import Authenticator, NintendoParental
from pynintendoparental.exceptions import InvalidSessionTokenException
_LOGGER = logging.getLogger(__name__)
async def main():
"""Running function"""
login = True
while login:
try:
if input("Should we use a session token? [N/y] ").upper() == "Y":
auth = await Authenticator.complete_login(None, input("Token: "), True)
else:
auth = Authenticator.generate_login()
_LOGGER.info("Login using %s", auth.login_url)
auth = await Authenticator.complete_login(auth, input("Response URL: "), False)
_LOGGER.info("Logged in, ready.")
_LOGGER.debug("Access token is: %s", auth.access_token)
control = await NintendoParental.create(auth)
login = False
except InvalidSessionTokenException as err:
_LOGGER.error("Invalid session token provided: %s", err)
except Exception as err:
_LOGGER.critical(err)
while True:
for device in control.devices.values():
_LOGGER.debug("Discovered device %s, label %s", device.device_id, device.name)
_LOGGER.debug(device.extra)
for usage in device.daily_summaries:
_LOGGER.debug("Discovered daily summary %s", usage)
for player in device.players:
_LOGGER.debug("Discovered player %s with %s playtime",
player.player_id,
player.playing_time)
_LOGGER.debug("Usage today %s", device.today_playing_time)
await device.update_max_daily_playtime(minutes=15)
_LOGGER.debug("ping")
await asyncio.sleep(15)
_LOGGER.debug("pong")
await control.update()
if __name__ == "__main__":
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(name)s %(levelname)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())