-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
131 lines (96 loc) · 3.41 KB
/
main.py
File metadata and controls
131 lines (96 loc) · 3.41 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import math as m
import datetime as dt
import os
import json
from sys import platform
with open("config.json") as config_file:
config = json.load(config_file)
class Gtime:
"""Gavin's time of day object"""
def __init__(self, int_time):
if type(int_time) is int:
self.minutes = int_time % 100
self.hours = m.floor(int_time / 100)
elif type(int_time) is Gtime:
self.minutes = int_time.minutes
self.hours = int_time.hours
def __sub__(self, other_Gtime):
hour_dif = (self.hours - other_Gtime.hours) * 100
min_dif = self.minutes - other_Gtime.minutes
if min_dif < 0:
hour_dif -= 100
min_dif += 60
if min_dif >= 60:
hour_dif += 100
min_dif -= 60
return Gtime(hour_dif + min_dif)
def __add__(self, other_Gtime):
hour_sum = (self.hours + other_Gtime.hours) * 100
min_sum = self.minutes + other_Gtime.minutes
if min_sum < 0:
hour_sum -= 100
min_sum += 60
if min_sum >= 60:
hour_sum += 100
min_sum -= 60
return Gtime(hour_sum + min_sum)
def __lt__(self, other_Gtime):
return self.to_int() < Gtime(other_Gtime).to_int()
def __gt__(self, other_Gtime):
return self.to_int() > Gtime(other_Gtime).to_int()
def __le__(self, other_Gtime):
return self.to_int() <= Gtime(other_Gtime).to_int()
def __ge__(self, other_Gtime):
return self.to_int() >= Gtime(other_Gtime).to_int()
def __eq__(self, other_Gtime):
return self.to_int() == Gtime(other_Gtime).to_int()
def c_time():
dt_current = dt.datetime.now().time()
return Gtime(100 * dt_current.hour + dt_current.minute)
def to_int(self):
return 100 * self.hours + self.minutes
def in_timerange(self, other_Gtime_range: tuple):
return other_Gtime_range[0] >= self and other_Gtime_range[1] < self
class Schedule:
def __init__(self, courses: dict):
self.courses = {}
for color in courses:
self.courses[color] = {}
self.courses[color]["name"] = courses[color]["name"]
self.courses[color]["meet_link"] = courses[color]["meet_link"]
def get_day():
return dt.datetime.today().weekday()
def timed_index(time, arr_ignore:list = []):
time_to_find = Gtime(time)
day = Schedule.get_day()
# print((config["timings"][day]))
for idx, val in enumerate(config["timings"][day]):
if config["period"][config["schedule"][day][idx]] in arr_ignore:
continue
if Gtime(config["timings"][day][idx][1]) > time_to_find:
return idx
if idx > 0 and Gtime(config["timings"][day][idx][1]) < time_to_find and Gtime(config["timings"][day][idx - 1][1]) >= time_to_find:
return idx
return False
def get_color(time, arr_ignore:list = []):
day = Schedule.get_day()
return config["period"][config["schedule"][day][Schedule.timed_index(time, arr_ignore=arr_ignore)]]
def get_class_name(self, time, arr_ignore:list = []):
day = Schedule.get_day()
return self.courses[Schedule.get_color(time, arr_ignore=arr_ignore)]["name"]
def get_next_meet_link(self, time, arr_ignore:list = []):
timef = Gtime(time)
day = Schedule.get_day()
color = Schedule.get_color(timef, arr_ignore=arr_ignore)
return self.courses[color]["meet_link"]
data = config["classes"]
schd = Schedule(data)
time = Gtime.c_time()
# time = 920
# next_class = schd.get_class_name(time, arr_ignore=config["noclass"])
link = schd.get_next_meet_link(time, arr_ignore=config["noclass"])
if link:
if platform == "win32" or platform == "cygwin":
os.system(f'start {config["browser"]} "{link}"')
else:
os.system(f'{config["browser"]} "{link}"')