Merge https://vcs.maemo.org/git/pywienerlinien
[pywienerlinien] / wlSearch.py
1 import urllib
2 import sys
3 from datetime import datetime
4 import settings
5 import webbrowser
6 import urllib2
7
8
9 class Search:
10
11     def __init__(self, origin, destination, origin_type='stop', destination_type='stop'):
12         self.origin = origin
13         self.destination = destination
14         self.origin_type = origin_type
15         self.destination_type = destination_type
16
17     def get_html(self, dtime=datetime.now()):
18         return urllib2.urlopen('%s?%s' % (settings.action, self.get_parameter(dtime)))
19
20     def open_browser(self, dtime=datetime.now()):
21         webbrowser.open('%s?%s' % (settings.action, self.get_parameter(dtime)))
22
23     def get_datetime(self, dtime):
24         return (dtime.strftime('%d.%m.%Y'), dtime.strftime('%H:%M'))
25
26     def get_parameter(self, dtime):
27         date, time = self.get_datetime(dtime)
28
29         post = {'language': 'de',
30             'sessionID': 0,
31             'requestID': 0,
32             'execInst': 'normal',
33             'command': '',
34             'anySigWhenPerfectNoOtherMatches': 1,
35             'itdLPxx_locationServerActive': '',
36             'locationServerActive': 0,
37             'typeInfo_origin': 'invalid',
38             'placeState_origin': 'empty',
39             'placeInfo_origin': 'invalid',
40             'place_origin': 'Wien',
41             'type_origin': self.origin_type, # stop/address/poi
42             'nameState_origin': 'empty',
43             'nameInfo_origin': 'invalid',
44             'anyType_origin': '',
45             'name_origin': self.origin,
46             'typeInfo_destination': 'invalid',
47             'placeState_destination': 'empty',
48             'placeInfo_destination': 'invalid',
49             'place_destination': 'Wien',
50             'type_destination': self.destination_type, # stop/address/poi
51             'nameState_destination': 'empty',
52             'nameInfo_destination': 'invalid',
53             'anyType_destination': '',
54             'name_destination': self.destination,
55             'itdTripDateTimeDepArr': 'dep',
56             'itdDateDayMonthYear': date, # DD.MM.YYYY
57             'itdTime': time, # HH:MM
58             'submitbutton': 'SUCHEN'
59         }
60
61         params = urllib.urlencode(post)
62         return params