#!/usr/bin/env python # -*- coding: utf-8 -*- import argparse from gotovienna.realtime import * parser = argparse.ArgumentParser(description='Get realtime public transport information for Vienna') parser.add_argument('-l', metavar='name', type=str, help='line name') parser.add_argument('-s', metavar='name', type=str, help='station name') args = parser.parse_args() itip = ITipParser() lines = itip.lines if args.l: l = args.l.upper() else: l = None if args.s: s = args.s.decode('UTF-8') else: s = '' if l and l in lines: stations = itip.get_stations(l) for key in stations.keys(): if not s: print '* %s:' % key for station in stations[key]: if s: if s.startswith(station[0]) or station[0].startswith(s): # FIXME print '* %s\n %s .....' % (key, station[0]), itip.get_departures(station[1]) else: print ' %s' % station[0] elif not l: ITEMS_PER_LINE = 12 ITEM_WIDTH = 5 LINE_WIDTH = (ITEMS_PER_LINE*ITEM_WIDTH + ITEMS_PER_LINE) print for label, remaining in categorize_lines(lines.keys()): prefix, fill, postfix = '|== ', '=', '==- -' before, after = prefix+label+' ', postfix padding = LINE_WIDTH - len(before+after) print ''.join((before, fill*padding, after)) while remaining: this_row = [remaining.pop(0) for _ in range(min(len(remaining), ITEMS_PER_LINE))] print ' '.join(('%%%ds' % ITEM_WIDTH) % x for x in this_row) print