forked from droso-hass/idfm-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
42 lines (34 loc) · 1.44 KB
/
cli.py
File metadata and controls
42 lines (34 loc) · 1.44 KB
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
from idfm_api import IDFMApi
from idfm_api.models import TransportType
import asyncio
import aiohttp
async def main():
session = aiohttp.ClientSession()
apikey = input("Enter API KEY:")
idfm = IDFMApi(session, apikey)
lines = await idfm.get_lines(TransportType.TRAIN)
for i, val in enumerate(lines):
print(f"#{i} - {val.name}")
line = lines[int(input("Select line "))]
print("\n")
stops = await idfm.get_stops(line.id)
for i, val in enumerate(stops):
print(f"#{i} - {val.name}")
stop = stops[int(input("Select stop area "))]
print("\n")
directions = await idfm.get_destinations(stop.id)
for i, val in enumerate(directions):
print(f"#{i} - {val}")
d = input("Select direction (leave blank to display all) ")
dir = None if d == "" else directions[int(d)]
print("\n")
print("Traffic:")
for i in await idfm.get_traffic(stop.id, destination_name=dir):
print(f"Line {i.line_id} {i.note} - Destination {i.destination_name}: {i.schedule} - Currently at stop: {i.at_stop} - Platform: {i.platform} - Status: {i.status}")
print("\n")
print("Informations:")
for i in await idfm.get_infos(line.id):
print(f"{i.name} - Type {i.type} - Severity {i.severity}\nStart {i.start_time} - End {i.end_time}\n{i.message}")
await session.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())