skip station if terminal
[pywienerlinien] / itip
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import argparse
5
6 from gotovienna.realtime import *
7
8
9 parser = argparse.ArgumentParser(description='Get realtime public transport information for Vienna')
10 parser.add_argument('-l', metavar='name', type=str, help='line name')
11 parser.add_argument('-s', metavar='name', type=str, help='station name')
12
13 args = parser.parse_args()
14
15 itip = ITipParser()
16 lines = itip.lines
17 if args.l:
18     l = args.l.upper()
19 else:
20     l = None
21 if args.s:
22     s = args.s.decode('UTF-8')
23 else:
24     s = ''
25
26 if l and l in lines:
27     stations = itip.get_stations(l)
28     for key in stations.keys():
29         if not s:
30             print '* %s:' % key
31         for station in stations[key]:
32             if s:
33                 if s.startswith(station[0]) or station[0].startswith(s):
34                     if station[0] == key:
35                         # skip station if destination
36                         continue
37                     # FIXME
38                     print '* %s\n  %s .....' % (key, station[0]), itip.get_departures(station[1])
39             else:
40                 print '    %s' % station[0]
41 elif not l:
42     ITEMS_PER_LINE = 12
43     ITEM_WIDTH = 5
44     LINE_WIDTH = (ITEMS_PER_LINE*ITEM_WIDTH + ITEMS_PER_LINE)
45
46     print
47     for label, remaining in categorize_lines(lines.keys()):
48         prefix, fill, postfix = '|== ', '=', '==- -'
49         before, after = prefix+label+' ', postfix
50         padding = LINE_WIDTH - len(before+after)
51         print ''.join((before, fill*padding, after))
52
53         while remaining:
54             this_row = [remaining.pop(0) for _ in
55                     range(min(len(remaining), ITEMS_PER_LINE))]
56             print ' '.join(('%%%ds' % ITEM_WIDTH) % x for x in this_row)
57
58         print