X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=itip;h=a291720d46dcaf393e7791a3cd6dce734dfa26cc;hb=HEAD;hp=74503849e3ef6e6c0d79e26771aca71f808a7d03;hpb=d16f86f4f4b788ec687f61870f7adebd62a00bda;p=pywienerlinien diff --git a/itip b/itip index 7450384..a291720 100755 --- a/itip +++ b/itip @@ -1,22 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import argparse - +from gotovienna import argparse +from gotovienna.utils import * from gotovienna.realtime import * - -def inred(x): - return '\033[91m' + x + '\033[0m' - -def ingreen(x): - return '\033[92m' + x + '\033[0m' - -def inblue(x): - return '\033[94m' + x + '\033[0m' +from datetime import time parser = argparse.ArgumentParser(description='Get realtime public transport information for Vienna') -parser.add_argument('line', nargs='?') -parser.add_argument('station', nargs='?') +parser.add_argument('line', nargs='?', help='line name (e.g. 59A)') +parser.add_argument('station', nargs='?', help='station name (e.g. Karlsplatz)') args = parser.parse_args() @@ -41,7 +33,7 @@ if args.line in itip.lines: for stops in stations: # Pad station list with empty items for printing, so that # different-sized lists aren't truncated (with zip below) - stops.extend([('', '')]*(maxlength-len(stops))) + stops.extend([('', '')] * (maxlength - len(stops))) stations_table = zip(*stations) fmt = '%%-%ds' % ITEM_WIDTH @@ -50,15 +42,15 @@ if args.line in itip.lines: print print spacer, spacer.join(inblue(fmt % ('Richtung %s' % name)) for name in headers) - print spacer, spacer.join('-'*ITEM_WIDTH for name in headers) + print spacer, spacer.join('-' * ITEM_WIDTH for name in headers) def match_station(query, station): return query and station and (query.lower() in station.lower()) for row in stations_table: - print spacer, spacer.join(ingreen(fmt%name) + print spacer, spacer.join(ingreen(fmt % name) if match_station(args.station, name) - else fmt%name + else fmt % name for name, url in row) print @@ -73,8 +65,11 @@ if args.line in itip.lines: print # Format a departure time (in minutes from now) for display - def format_departure(minutes): - if minutes == 0: + def format_departure(departure): + minutes = departure['time'] + if type(minutes) == time: + return inblue(minutes.strftime('%H:%M')) + elif minutes == 0: return inred('now') elif minutes == 1: return inblue('1') + ' min' @@ -95,7 +90,7 @@ if args.line in itip.lines: else: ITEMS_PER_LINE = 12 ITEM_WIDTH = 5 - LINE_WIDTH = (ITEMS_PER_LINE*ITEM_WIDTH + ITEMS_PER_LINE) + LINE_WIDTH = (ITEMS_PER_LINE * ITEM_WIDTH + ITEMS_PER_LINE) if args.line: print @@ -104,10 +99,10 @@ else: print for label, remaining in categorize_lines(itip.lines): prefix, fill, postfix = '|== ', '=', '==- -' - before, after = prefix+label+' ', postfix - padding = LINE_WIDTH - len(before+after) + before, after = prefix + label + ' ', postfix + padding = LINE_WIDTH - len(before + after) before = before.replace(label, inblue(label)) - print ''.join((before, fill*padding, after)) + print ''.join((before, fill * padding, after)) while remaining: this_row = [remaining.pop(0) for _ in