Script to grab stop codes from allstops.xml and sort
[ottawa-travel-planner.git] / PlanTime.py
blobe7cd4859307a4cfff9057ccd46c14a2e951781da
2 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
4 import time
6 class PlanTime:
7 """Defines a trip time and constraint (e.g. MUST_LEAVE_AFTER)."""
8 def __init__(self, unixtime, constraint):
9 self.unixtime = unixtime
10 self.constraint = constraint
12 def toPlannerParams(self):
13 """Let's hope your timezone is Eastern. Otherwise this isn't going
14 to return the right times. I don't see a way to locally override
15 the timezone in Python without defining my own tzinfo subclass.
16 I do not feel like installing pytz."""
17 loc = time.localtime(self.unixtime)
18 ymd = time.strftime("%Y-%m-%d", loc)
19 params = (("dateSelect", ymd), ("day", ymd),
20 # visibleDay=June+6
21 ("visibleDay", time.strftime("%B ", loc) + str(loc.tm_mday)),
22 ("requestCode", self.constraint),
23 ("time", time.strftime("%I:%M", loc)),
24 ("timePeriod", time.strftime("%p", loc).lower()),
25 ("ok.x", 29), ("ok.y", 21))
26 return params
28 APPROX_ARRIVAL_TIME = 0
29 MUST_ARRIVE_BEFORE = 1
30 APPROX_DEPARTURE_TIME = 2
31 MUST_LEAVE_AFTER = 3
32 FIRST_TRIP = 4
33 LAST_TRIP = 5