-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
68 lines (58 loc) · 1.79 KB
/
main.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
import json
import os
from datetime import datetime
import webbrowser
from playsound import playsound
from pynotifier import Notification
timeToClassDict = {}
soundPath = os.path.join(os.path.dirname(__file__), 'data', 'sound.ogg')
def playSound():
playsound(soundPath)
def notify(subject, link):
# if os.name == 'nt':
# icon = "data/classroom.ico"
# else:
# icon = "data/classroom.png"
Notification(
title='Upcoming Class - ' + subject,
description='Opening - ' + link,
icon_path="accessories-text-editor", # On Windows .ico is required, on Linux - .png
duration=5 # Duration in seconds
).send()
def startClass(subject, link):
notify(subject, link)
playSound()
webbrowser.open(link)
print("Successfully opened.")
def checkClass():
d = datetime.now()
day = d.weekday()
hour = d.hour
time = day*24 + hour
print('---------------------------')
print(str(d))
if time in timeToClassDict:
class_ = timeToClassDict[time]
subject = class_['subject']
link = class_['link']
print(subject + " class right now.")
startClass(subject, link)
else:
print("No class right now.")
# Getting the absolute path of the file
dataPath = os.path.join(os.path.dirname(__file__), 'class-data.json')
# Loading timetable from class-data.json
with open(dataPath) as f:
data = json.load(f)
for class_ in data:
subject = class_['subject']
link = class_['link']
for time in class_['timings']:
day = time['day']
hour = time['hour']
timeToClassDict[day*24 + hour] = {
'subject': subject,
'link': link,
}
if __name__ == '__main__':
checkClass()