-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
87 lines (68 loc) · 3.36 KB
/
run.py
File metadata and controls
87 lines (68 loc) · 3.36 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
import time
import sys
from datetime import datetime
from file_operations import time_data
from utility import formatting
from playsound import playsound
def main():
time_data.clean_records()
# check if the user passed a desired study time in minutes
users_input = None
try:
# attempt to convert the value to an integer. if it's null, an exception will be thrown
users_input = int(sys.argv[1].strip()) # strips empty space
# naked exception
except: # the user didn't pass another value
pass
MINUTES_TO_STUDY = users_input if users_input != None else 25 # sets MINUTES_TO_STUDY to what the user specified. if the user didn't specify then set it to 25 minutes.
MINUTES_FOR_BREAK = 5
# Pomodoro Technique implementation
STUDY_TIME = MINUTES_TO_STUDY * 60
# set the amount of seconds in break time
BREAK_TIME = MINUTES_FOR_BREAK * 60
# show the user how much time they've studied today
print('*-----------------------------------*')
time_data.print_todays_practice_progress()
print('*-----------------------------------*')
print(
f'It\'s currently { datetime.now().strftime("%d/%m/%Y %H:%M:%S") }')
# a counter to check where the time is sitting. It will reset each time a break has occured.
pomodoro_start = time.time()
# play sound effect for the beginning of the loop
playsound('./sounds/yeah-boy-memes-comedy-funny-amusing-jokes-114748.mp3')
while True:
# update the tracker's count
pomodoro_tracker = time.time()
# Adds a small sleep statement to cut down on the processing.
time.sleep(0.001)
# checks if the user has been studying for a study period.
if pomodoro_tracker - pomodoro_start >= STUDY_TIME:
playsound('./sounds/pixel-death-66829.mp3')
# play sound effect to alert the user
print(f"Warning: {MINUTES_FOR_BREAK}-minute break time!")
# write the study time to the file
formatted_runtime = formatting.format_seconds_to_hms(STUDY_TIME)
print(f"You just studied for {formatted_runtime}.")
# write the studied time to the file
time_data.write_new_record(STUDY_TIME)
# pause the program for 5 minutes
for _ in range(BREAK_TIME):
time.sleep(1)
# once the break completes, play a noise to the let the user know
# after each break, check if the user wants to keep studyig
continue_studying_check = input(
"Hello again! Would you like to keep studying (yes/no)? ").strip()
# check if the user's response is equal to anything in these lists
if(continue_studying_check.lower() in ['yes', 'y', 'yeah', 'sure']):
# reset the start of the time tracking to the current time. example: 35 (pomodoro_tracker) - 35 (pomodoro_start) = 0
print(
f'It\'s currently { datetime.now().strftime("%d/%m/%Y %H:%M:%S") }')
pomodoro_start = time.time()
playsound('./sounds/Mario-Kart-Race-Start-Gaming-Sound-Effect-HD.mp3')
elif(continue_studying_check.lower() in ['no', 'n', 'never', 'nah', 'nein']):
break
else:
print("Invalid input. Exiting study timer.")
break
if __name__ == "__main__":
main()