-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric_transit.py
60 lines (53 loc) · 2.06 KB
/
generic_transit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from datetime import date, time, datetime
import time
import configparser
def get_transit_departures(file_path:str, schedule_key:str):
parser = configparser.RawConfigParser()
parser.read(file_path)
data = []
data = parser.get(schedule_key, "schedule")
data = data.split(",")
return data
def next_transit():
# config from the file
#Setup array of morning bus times for the week
transit_weekly = get_transit_departures("generic_transit_schedules.ini","weekdays")
transit_sat = get_transit_departures("generic_transit_schedules.ini","saturdays")
transit_sun = get_transit_departures("generic_transit_schedules.ini","sundays")
transit_check_schedule = []
weekDay = datetime.now().strftime("%A")
if weekDay == "Saturday" :
transit_check_schedule = transit_sat
if weekDay == "Sunday" :
transit_check_schedule = transit_sun
if weekDay != "Saturday" or weekDay != "Sunday" :
transit_check_schedule = transit_weekly
#Initiate the array
buss_r = []
if len(transit_check_schedule) > 0 :
l = len(transit_check_schedule) - 1
else :
return []
stop_time = transit_check_schedule[l]
first_bus = transit_check_schedule[0]
print("Loading departures for "+weekDay)
print(str(len(transit_check_schedule))+" depatures loaded")
print("First departure is at: "+first_bus)
print("Last departure time is at: "+transit_check_schedule[l])
start_time = datetime.now().strftime("%H:%M)")
t = 0
if start_time < stop_time or len(transit_check_schedule) == 0:
print("No Transits to scan for...")
return buss_r
while t < len(transit_check_schedule):
if start_time >= transit_check_schedule[t]:
# print("Next ",t)
t = t +1
if (t+1) > len(transit_check_schedule):
break
if start_time < transit_check_schedule[t] :
while t < len(transit_check_schedule) :
#print("Adding departure "+transit_check_schedule[t].strftime("%H:%M"))
buss_r.append(transit_check_schedule[t])
t = t +1
return buss_r