-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprint-table.py
More file actions
57 lines (45 loc) · 1.68 KB
/
print-table.py
File metadata and controls
57 lines (45 loc) · 1.68 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 13:31:20 2019
@author: simon
"""
#%%
import json
import os
import optparse
parser = optparse.OptionParser('print-table.py')
parser.add_option('-i', '--table', dest='infile', type='string', help='input file to pretty print')
parser.add_option('-t', '--title', dest='title', type='string', help='title text before the print')
# parser.add_option('-d', '--dict', dest='dict', type='string', help='dict.json')
(opts, args) = parser.parse_args()
# default location
path_prefix = './timetables/'
path_table = path_prefix + 'timetable.arrival.special.json'
title = 'Zurich Airport ZRH - Arrivals (specials)'
if(opts.infile is not None):
if(os.path.exists(opts.infile)):
path_table = opts.infile
else:
raise FileNotFoundError('Input file not found: {}'.format(opts.infile))
if(opts.title is not None):
title = str(opts.title)
def main():
try:
with open(path_table) as stdFile:
table = json.load(stdFile)
print(title)
print('STA / Code / Reg / Type / City')
for flight in table['timetable']:
time_sched = flight['scheduled']
code = flight['flightcode']
reg = flight['masterflight']['registration']
plane = flight['masterflight']['aircrafttype']
city = flight['airportinformation']['airport_city']
print(time_sched + ' ' + code + ' ' + reg + ' ' + plane + ' ' + city)
# enables abortion of the program through CTRL + C
except KeyboardInterrupt:
print('')
exit(0)
if __name__ == '__main__':
main()