aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-06 22:11:42 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-06 22:11:42 +0100
commit5e660cce38c02d29c7d5cb850bb8ec9633e7a0f8 (patch)
tree22ac19fb45d21fd4379baae5ff03966b04503bc0
parent2c05297468cf53301646cc3ff9b355a3f232a891 (diff)
fix typo and add max minutes late variable for lazy students
-rwxr-xr-xautoplanner.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/autoplanner.py b/autoplanner.py
index c79dff4..438ab7e 100755
--- a/autoplanner.py
+++ b/autoplanner.py
@@ -12,9 +12,15 @@ from shared import *
import sys
from datetime import datetime
-DAY = 24 * 60 * 60
+SECOND = 1
+MINUTE = 60 * SECOND
+HOUR = 60 * MINUTE
+DAY = 24 * HOUR
+
# don't calculate trip for events further than a week in the future
-FUTURE_MAX = DAY * 7
+FUTURE_MAX = 7 * DAY
+# allow trips to end two minutes late (lazy student mode)
+LATE_MAX = 2 * MINUTE
cal = Calendar()
KEY = ""
@@ -62,9 +68,9 @@ def leg2desc(leg):
def trip2ical(trip, real_date):
trips = trip['trips']
trips = [t for t in trips if t['status'] != 'CANCELLED']
- trips = [t for t in trips if dateutil.parser.parse(t['legs'][-1]['destination']['plannedDateTime']).timestamp() > real_date.timestamp()]
+ trips = [t for t in trips if dateutil.parser.parse(t['legs'][-1]['destination']['plannedDateTime']).timestamp() < (real_date.timestamp() + LATE_MAX)]
actual_trip = next(reversed(trips))
- if actual_trip == None: return
+ if actual_trip == None: return # no trip possible
for leg in actual_trip['legs']:
if leg['travelType'] == 'WALK': continue