-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarter.py
96 lines (81 loc) · 3.1 KB
/
Starter.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
from datetime import timedelta
from os import system as cmd
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "true"
from pygame import mixer
import threading
import sys
import time
def suffixed_time_to_int(string_representation_of_time: str) -> int:
"""
This function takes something like `"2m 6h 1s"` and returns back the time duration in seconds (int)
"""
time = string_representation_of_time.strip().split()
for i in range(len(time)):
if time[i].endswith("s"):
time[i] = int(time[i][:-1])
elif time[i].endswith("m"):
time[i] = int(time[i][:-1]) * 60
elif time[i].endswith("h"):
time[i] = int(time[i][:-1]) * 60 * 60
elif time[i].endswith("d"):
time[i] = int(time[i][:-1]) * 60 * 60 * 24
else:
raise ValueError("Proper duration not passed")
return sum(time)
# Timer
def timer(end_timestamp):
while True:
time_left = str(timedelta(seconds=end_timestamp-int(time.time())))
print("\rSession Ending In: ", time_left, end="")
time.sleep(1)
sys.stdout.flush()
if time_left == "0:00:00" or time_left == "00:00:00":
break
print("\n\n-------------------------------\nThe Study Session has ended, please \nClose this window to shut down the \nDiscord Activity\n-------------------------------")
# Playing the Notification Sound
mixer.init()
mixer.music.load('notification.ogg')
while True:
mixer.music.play()
time.sleep(3)
# Introduction
print(
'''
-----------------------------------------------------------------
STUDY SESSION TIMER AND DISCORD ACTIVITY DISPLAYER
Developed by Zacky
(utilizes Pizzabelly/EasyRP)
-----------------------------------------------------------------
'''
)
# Getting the status report
study_duration: int = suffixed_time_to_int(input("How long will this study session last?\n(for e.g. 2h 6m 1s)\nOnce the session is over, a notification sound will play\n> "))
status: str = input("\nWhat is your current status?\n(for e.g. Studied 2 hours so far, or, Trying to focus)\n> ").strip()
start_timestamp: int = int(time.time())
end_timestamp: int = start_timestamp + study_duration
EasyRPConfig: str = '''
[Identifiers]
ClientID=893044045541179392
[State]
State={status}
Details={study_duration_hours} Hour Study Session
StartTimestamp={start_timestamp}
EndTimestamp={end_timestamp}
[Images]
LargeImage=studybagbig
LargeImageTooltip=Focusing
SmallImage=
SmallImageTooltip=
'''
f = open("config.ini", "w+")
f.write(EasyRPConfig.format(
start_timestamp=start_timestamp, end_timestamp=end_timestamp, status=status, study_duration_hours=round(study_duration/3600, 1)))
f.close()
t1 = threading.Thread(target=cmd, args=("\"easyrp.exe\"", ))
t2 = threading.Thread(target=timer, args=(end_timestamp, ))
print("\n-------------------------------\nStarting the rish presence activity program now...")
t1.start()
time.sleep(3)
print("\n-------------------------------")
t2.start()