skip station if terminal
[pywienerlinien] / itip
diff --git a/itip b/itip
index b8fe1bf..049a17d 100755 (executable)
--- a/itip
+++ b/itip
@@ -1,14 +1,9 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-from BeautifulSoup import BeautifulSoup
-from urllib2 import urlopen
-import settings
-from datetime import time
 import argparse
-import re
 
-from gotovienna.realtime import ITipParser
+from gotovienna.realtime import *
 
 
 parser = argparse.ArgumentParser(description='Get realtime public transport information for Vienna')
@@ -36,27 +31,28 @@ if l and l in lines:
         for station in stations[key]:
             if s:
                 if s.startswith(station[0]) or station[0].startswith(s):
+                    if station[0] == key:
+                        # skip station if destination
+                        continue
                     # FIXME
                     print '* %s\n  %s .....' % (key, station[0]), itip.get_departures(station[1])
             else:
                 print '    %s' % station[0]
-
 elif not l:
-    line = {'U-Bahn': '|', 'Strassenbahn': '|', 'Bus': '|', 'Andere': '|', 'Nightline': '|'}
-    lines_sorted = lines.keys()
-    lines_sorted.sort()
-    for li in lines_sorted:
-        if li.isdigit():
-            type = 'Strassenbahn'
-        elif li.endswith('A') or li.endswith('B') and li[1].isdigit():
-            type = 'Bus'
-        elif li.startswith('U'):
-            type = 'U-Bahn'
-        elif li.startswith('N'):
-            type = 'Nightline'
-        else:
-            type = 'Andere'
-
-        line[type] += ' %s |' % li
-    for kv in line.items():
-        print "%s:\n%s" % kv
+    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