+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
from BeautifulSoup import BeautifulSoup, NavigableString
from urllib2 import urlopen
from urllib import urlencode
from textwrap import wrap
import argparse
import sys
+import os.path
POSITION_TYPES = ('stop', 'address', 'poi')
TIMEFORMAT = '%H:%M'
+DEBUGLOG = os.path.expanduser('~/gotoVienna.debug')
class ParserError(Exception):
params = urlencode(post)
url = '%s?%s' % (settings.action, params)
- print "\nurl %s url\n\n%s\n\nurl %s url\n" % ('~' * 100, url, '~' * 100)
+ try:
+ f = open(DEBUGLOG, 'a')
+ f.write(url + '\n')
+ f.close()
+ except:
+ print 'Unable to write to DEBUGLOG: %s' % DEBUGLOG
return urlopen(url)
@classmethod
def get_price(cls, x):
y = rParser.get_tdtext(x, 'col_price')
+ if y == '*':
+ return 0.0
if y.find(','):
return float(y.replace(',', '.'))
else:
try:
self._overview = self._parse_overview()
except AttributeError:
- f = open('DEBUG', 'w')
+ f = open(DEBUGLOG, 'w')
f.write(str(self.soup))
f.close()
parser.add_argument('-dt', metavar='type', type=str, help='destination type: %s' % ' | '.join(POSITION_TYPES), default='stop', choices=POSITION_TYPES)
args = parser.parse_args()
- print args.o
html = search((args.o, args.ot), (args.d, args.dt)).read()
parser = sParser(html)
details = parser.details
l = ''
while not l == 'q':
- for r in range(len(overviews)):
- print '%d. [%s] %s-%s (%s)' % (r + 1, overviews[r]['date'], overviews[r]['time'][0], overviews[r]['time'][1], overviews[r]['duration'])
+ for idx, overview in enumerate(overviews):
+ if not overview['date'] or not overview['time']:
+ # XXX: Bogus data for e.g. Pilgramgasse->Karlsplatz?!
+ continue
+
+ print '%d. [%s] %s-%s (%s)' % (idx + 1,
+ overview['date'],
+ overview['time'][0],
+ overview['time'][1],
+ overview['duration'])
print 'q. Quit'
l = sys.stdin.readline().strip()
print