fixing routing.py bug, if time is 24:00
[pywienerlinien] / extractor.py
1 #!/usr/bin/env python
2
3 from gotovienna.utils import *
4 from gotovienna.realtime import *
5
6 itip = ITipParser()
7
8 def get_lines():
9     return categorize_lines(itip.lines)
10
11 def get_stations(line):
12     return itip.get_stations(line).items()
13
14 def remove_duplicates(lst):
15     outlist = []
16     for element in lst:
17         if element not in outlist:
18             outlist.append(element)
19     return outlist
20
21 def get_all_stations():
22     st = {}
23     for type, lines in get_lines():
24         for line in lines:
25             st[line] = {}
26             for direction in get_stations(line):
27                 st[line][direction[0]] = map(lambda x: x[0], direction[1])
28     return st
29
30 if __name__ == "__main__":
31     with open('extracted.wki', 'w') as f:
32         for typ, lines in get_lines():
33             f.write('== %s ==\n' % typ)
34             #print (' %s ' % typ).center(79, '*')
35             for line in lines:
36                 f.write('=== %s ===\n' % line)
37                 for direction in get_stations(line):
38                     #print
39                     f.write('==== %s ====\n' % direction[0].encode('utf-8'))
40                     #print line + " " + (' %s ' % direction[0]).center(77 - len(line) * 2, '=') + " " + line
41                     # use remove_duplicates(direction[1]) if necessary 
42                     for station, _ in direction[1]:
43                         f.write(' * %s\n' % station.encode('utf-8'))
44                         #print station.center(79)
45             f.flush()
46             #print