1 # -*- coding: utf-8 -*-
5 from datetime import datetime
10 from parseHtml import Parser
12 from PySide.QtCore import Qt
13 from PySide.QtDeclarative import QDeclarativeView
15 def QMLModel(overview):
16 # Mapping from the "overview" data structure to a "plain" data
17 # structure to be used as model for the qml listview
21 'date': item['date'].strftime('%d.%m.%Y') if item['date'] else u'Fußweg',
22 'duration': item['duration'].strftime('%H:%M'),
23 'price': item['price'],
24 'change': item['change'],
27 if len(item['time']) == 2 and all(x is not None for x in item['time']):
29 'time_from': item['time'][0].strftime('%H:%M'),
30 'time_to': item['time'][1].strftime('%H:%M'),
33 d.update({'time_from': '-', 'time_to': '-'})
41 def __init__(self, origin, destination, origin_type='stop', destination_type='stop', parent=None):
43 self.destination = destination
44 self.origin_type = origin_type
45 self.destination_type = destination_type
50 def get_html(self, dtime=datetime.now()):
51 return urllib2.urlopen('%s?%s' % (settings.action, self.get_parameter(dtime)))
53 def open_browser(self, dtime=datetime.now()):
54 webbrowser.open('%s?%s' % (settings.action, self.get_parameter(dtime)))
56 def open_qml(self, dtime=datetime.now()):
57 p = Parser(self.get_html(dtime))
58 self.qml_model = QMLModel(p.overview)
59 self.view = QDeclarativeView(self.parent)
60 self.view.setWindowTitle('Search results')
61 self.view.setWindowFlags(Qt.Window)
62 self.view.setAttribute(Qt.WA_Maemo5StackedWindow)
63 self.view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
64 self.view.setSource('ui/Overview.qml')
65 self.view.rootObject().setProperty('model', self.qml_model)
68 def get_datetime(self, dtime):
69 return (dtime.strftime('%d.%m.%Y'), dtime.strftime('%H:%M'))
71 def get_parameter(self, dtime):
72 date, time = self.get_datetime(dtime)
74 post = {'language': 'de',
79 'anySigWhenPerfectNoOtherMatches': 1,
80 'itdLPxx_locationServerActive': '',
81 'locationServerActive': 0,
82 'typeInfo_origin': 'invalid',
83 'placeState_origin': 'empty',
84 'placeInfo_origin': 'invalid',
85 'place_origin': 'Wien',
86 'type_origin': self.origin_type, # stop/address/poi
87 'nameState_origin': 'empty',
88 'nameInfo_origin': 'invalid',
90 'name_origin': self.origin,
91 'typeInfo_destination': 'invalid',
92 'placeState_destination': 'empty',
93 'placeInfo_destination': 'invalid',
94 'place_destination': 'Wien',
95 'type_destination': self.destination_type, # stop/address/poi
96 'nameState_destination': 'empty',
97 'nameInfo_destination': 'invalid',
98 'anyType_destination': '',
99 'name_destination': self.destination,
100 'itdTripDateTimeDepArr': 'dep',
101 'itdDateDayMonthYear': date, # DD.MM.YYYY
102 'itdTime': time, # HH:MM
103 'submitbutton': 'SUCHEN'
106 params = urllib.urlencode(post)