-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
executable file
·38 lines (30 loc) · 1.18 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
#!/usr/bin/env python3
"""Example code."""
import asyncio
import logging
import sys
from asyncio import CancelledError
import aiohttp
from aiohttp.client_exceptions import ClientError
import shellrecharge
from shellrecharge import LocationEmptyError, LocationValidationError
async def main():
"""Main module."""
# Some random stations
location_ids = ["9b9428ab-1dfd-4230-a024-084eacf776ff", "682154", "9cf6c16b-b043-4ba8-b7ca-872f82a0faf4"]
async with aiohttp.ClientSession() as session:
try:
api = shellrecharge.Api(session)
for location_id in location_ids:
location = await api.location_by_id(location_id)
logging.info(location)
except LocationEmptyError:
logging.error("No data returned, check location id")
except LocationValidationError as err:
logging.error("Location validation error {}, report location id" % err)
except (ClientError, TimeoutError, CancelledError) as err:
logging.error(err)
if __name__ == "__main__":
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
loop = asyncio.new_event_loop()
loop.run_until_complete(main())