Restructuring; removing ui files
[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                     # FIXME
35                     print '* %s\n  %s .....' % (key, station[0]), itip.get_departures(station[1])
36             else:
37                 print '    %s' % station[0]
38
39 elif not l:
40     line = {'U-Bahn': '|', 'Strassenbahn': '|', 'Bus': '|', 'Andere': '|', 'Nightline': '|'}
41     lines_sorted = lines.keys()
42     lines_sorted.sort()
43     for li in lines_sorted:
44         if li.isdigit():
45             type = 'Strassenbahn'
46         elif li.endswith('A') or li.endswith('B') and li[1].isdigit():
47             type = 'Bus'
48         elif li.startswith('U'):
49             type = 'U-Bahn'
50         elif li.startswith('N'):
51             type = 'Nightline'
52         else:
53             type = 'Andere'
54
55         line[type] += ' %s |' % li
56     for kv in line.items():
57         print "%s:\n%s" % kv