1 # -*- coding: utf-8 -*-
5 from datetime import datetime
10 from parseHtml import Parser
12 from PySide.QtDeclarative import QDeclarativeView
14 def QMLModel(overview):
15 # Mapping from the "overview" data structure to a "plain" data
16 # structure to be used as model for the qml listview
20 'date': item['date'].strftime('%d.%m.%Y') if item['date'] else u'Fußweg',
21 'duration': item['duration'].strftime('%H:%M'),
22 'price': item['price'],
23 'change': item['change'],
26 if len(item['time']) == 2 and all(x is not None for x in item['time']):
28 'time_from': item['time'][0].strftime('%H:%M'),
29 'time_to': item['time'][1].strftime('%H:%M'),
32 d.update({'time_from': '-', 'time_to': '-'})
40 def __init__(self, origin, destination, origin_type='stop', destination_type='stop'):
42 self.destination = destination
43 self.origin_type = origin_type
44 self.destination_type = destination_type
48 def get_html(self, dtime=datetime.now()):
49 return urllib2.urlopen('%s?%s' % (settings.action, self.get_parameter(dtime)))
51 def open_browser(self, dtime=datetime.now()):
52 webbrowser.open('%s?%s' % (settings.action, self.get_parameter(dtime)))
54 def open_qml(self, dtime=datetime.now()):
55 p = Parser(self.get_html(dtime))
56 self.qml_model = QMLModel(p.overview)
57 self.view = QDeclarativeView()
58 self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
59 self.view.setSource('ui/Overview.qml')
60 self.view.rootObject().setProperty('model', self.qml_model)
63 def get_datetime(self, dtime):
64 return (dtime.strftime('%d.%m.%Y'), dtime.strftime('%H:%M'))
66 def get_parameter(self, dtime):
67 date, time = self.get_datetime(dtime)
69 post = {'language': 'de',
74 'anySigWhenPerfectNoOtherMatches': 1,
75 'itdLPxx_locationServerActive': '',
76 'locationServerActive': 0,
77 'typeInfo_origin': 'invalid',
78 'placeState_origin': 'empty',
79 'placeInfo_origin': 'invalid',
80 'place_origin': 'Wien',
81 'type_origin': self.origin_type, # stop/address/poi
82 'nameState_origin': 'empty',
83 'nameInfo_origin': 'invalid',
85 'name_origin': self.origin,
86 'typeInfo_destination': 'invalid',
87 'placeState_destination': 'empty',
88 'placeInfo_destination': 'invalid',
89 'place_destination': 'Wien',
90 'type_destination': self.destination_type, # stop/address/poi
91 'nameState_destination': 'empty',
92 'nameInfo_destination': 'invalid',
93 'anyType_destination': '',
94 'name_destination': self.destination,
95 'itdTripDateTimeDepArr': 'dep',
96 'itdDateDayMonthYear': date, # DD.MM.YYYY
97 'itdTime': time, # HH:MM
98 'submitbutton': 'SUCHEN'
101 params = urllib.urlencode(post)