forked from chuwyton/TokyoGTFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrains_realtime.py
52 lines (40 loc) · 1.39 KB
/
trains_realtime.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
import argparse
import time
import sys
import os
from src.rt_trains import TrainRealtime
from src.const import HEADER
if __name__ == "__main__":
args_parser = argparse.ArgumentParser()
args_parser.add_argument(
"-a", "--apikey", metavar="YOUR-APIKEY",
help="apikey from api.odpt.org"
)
args_parser.add_argument(
"-g", "--gtfs", metavar="PATH-TO-TRAINS-GTFS.zip", default="tokyo_trains.zip",
help="path to GTFS created by trains_gtfs.py"
)
args_parser.add_argument(
"-hr", "--human-readable", action="store_true",
help="output gtfs-realtime file as human-readable instead of binary"
)
args = args_parser.parse_args()
# Apikey checks
if args.apikey:
apikey = args.apikey
elif os.path.exists("apikey.txt"):
with open("apikey.txt", mode="r", encoding="utf8") as f:
apikey = f.read().strip()
else:
sys.exit(
"No apikey!\n"
"Provide it inside command line argument '--apikey',\n"
"Or put it inside a file named 'apikey.txt'."
)
start_time = time.time()
print(HEADER)
print("=== Trains GTFS-RT: Starting! ===")
print("Warming up")
TrainRealtime.parse_once(apikey, args.human_readable, args.gtfs)
total_time = time.time() - start_time
print("=== TokyoGTFS: Finished in {} s ===".format(round(total_time, 2)))