-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-join.py
executable file
·106 lines (87 loc) · 3.08 KB
/
class-join.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
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
#!/usr/bin/env python3
import json
import os
import sys
try:
import datetime
except:
consent = input(
"This program requires datetime module. Should we install it for you? (y/n)")
if consent == 'y' or consent == '':
os.system('python3 -m pip install datetime')
print('datetime module installed.')
print("Please re-open the terminal and/or run this program again.")
input('Press enter to exit.')
quit()
else:
print('You have declined to install the module.')
input('Press enter to exit.')
quit()
def load_json(path):
with open(path, 'r') as f:
return json.load(f)
def get_weekday():
return datetime.date.today().strftime('%A')
def get_time():
return int(datetime.datetime.now().strftime('%H%M'))
def select_class(jsonobj):
weekday = get_weekday()
time = int(get_time())
if weekday in jsonobj:
if time >= 1000 and time < 1015:
class_rn = jsonobj['form_class'][0]
elif time >= 1015 and time < 1105:
class_rn = jsonobj[weekday][0]
elif time >= 1105 and time < 1200:
class_rn = jsonobj[weekday][1]
else:
print('There is no class at this time.')
input('Press enter to exit.')
sys.exit()
else:
print('There is no class at this time.')
input('Press enter to exit.')
sys.exit()
return class_rn
def parse_class(class_rn):
class_period = class_rn['period']
class_teacher = class_rn['teacher']
class_link = class_rn['link']
return class_period, class_teacher, class_link
def class_msg(class_period, class_teacher, class_link):
if class_period == '':
print('You are joining the form class.')
print('Form teacher is: ' + class_teacher)
print("The link we're going to use is: " + class_link)
consent = input('Do you consent to join the class? (y/n) ')
if consent == 'y' or consent == '':
class_open(class_link)
else:
print('You have declined to join the class.')
input('Press enter to exit.')
quit()
else:
print('You are joining class no ' + class_period + '.')
print('Teacher is: ' + class_teacher)
print("The link we're going to use is: " + class_link)
consent = input('Do you consent to join the class? (y/n) ')
if consent == 'y' or consent == '':
class_open(class_link)
else:
print('You have declined to join the class.')
input('Press enter to exit.')
quit()
def class_open(class_link):
if sys.platform == 'win32':
os.system('start "" "' + class_link + '"')
elif sys.platform == 'linux':
os.system('xdg-open ' + class_link)
elif sys.platform == 'darwin':
os.system('open ' + class_link)
def main():
jsonobj = load_json('class-routine.json')
class_rn = select_class(jsonobj)
class_period, class_teacher, class_link = parse_class(class_rn)
class_msg(class_period, class_teacher, class_link)
if __name__ == '__main__':
main()