From a56d1458a5dce390dd361eb0ba51479947ab81ca Mon Sep 17 00:00:00 2001 From: Florian Schweikert Date: Sat, 14 Jan 2012 04:45:10 +0100 Subject: [PATCH] extract lines and stations from itip parse line names and their stations from wienerlinien.at/itip and save them in wiki styled text --- extractor.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 extractor.py diff --git a/extractor.py b/extractor.py new file mode 100644 index 0000000..de6fe99 --- /dev/null +++ b/extractor.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +from gotovienna.utils import * +from gotovienna.realtime import * + +itip = ITipParser() + +def get_lines(): + return categorize_lines(itip.lines) + +def get_stations(line): + return itip.get_stations(line).items() + +def remove_duplicates(lst): + outlist = [] + for element in lst: + if element not in outlist: + outlist.append(element) + return outlist + +def get_all_stations(): + st = {} + for type, lines in get_lines(): + for line in lines: + st[line] = {} + for direction in get_stations(line): + st[line][direction[0]] = map(lambda x: x[0], direction[1]) + return st + +if __name__ == "__main__": + with open('extracted.wki', 'w') as f: + for typ, lines in get_lines(): + f.write('== %s ==\n' % typ) + #print (' %s ' % typ).center(79, '*') + for line in lines: + f.write('=== %s ===\n' % line) + for direction in get_stations(line): + #print + f.write('==== %s ====\n' % direction[0].encode('utf-8')) + #print line + " " + (' %s ' % direction[0]).center(77 - len(line) * 2, '=') + " " + line + # use remove_duplicates(direction[1]) if necessary + for station, _ in direction[1]: + f.write(' * %s\n' % station.encode('utf-8')) + #print station.center(79) + f.flush() + #print -- 1.7.9.5