This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
147 lines (113 loc) · 3.67 KB
/
utilities.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import os
from time import sleep, time
from config import *
def clear_screen():
print('\n' * TERMINAL_HEIGHT)
def load_data(filepath):
with open(filepath, 'r') as f:
data = f.read()
return data
def does_file_exist(filepath):
try:
data = load_data(filepath)
except FileNotFoundError:
return False
return True
def load_routine_data(filepath):
try:
data = load_data(filepath)
except FileNotFoundError:
print('Routine Not Found')
return
data = data.split('\n')
routine = {}
current_field = ''
for line in data:
line = line.strip()
if line == '' or line[0] == '#':
continue
elif line[-1] == ':':
current_field = line[:-1]
routine[current_field] = []
elif ':' in line and ':' != line[-1]:
current_field, value = line.split(':')
routine[current_field] = int(value.strip())
else:
item = line.strip()
routine[current_field].append(line.strip())
print('Routine loaded.')
return routine
def print_loaded_routine(routine):
print()
for i, exercise in enumerate(routine['exercises']):
print(f"Exercise {i+1}: {Colors.WHITE}{exercise}{Colors.NORMAL}")
print()
print(f"Exercise Time: {Colors.WHITE}{routine['exercise_time']}{Colors.NORMAL}")
print(f"Rest Time: {Colors.WHITE}{routine['rest_time']}{Colors.NORMAL}")
print(f"Reps: {Colors.WHITE}{routine['reps']}{Colors.NORMAL}")
print()
def get_routine_data():
exercises = get_exercises()
exercise_time = get_exercise_time()
rest_time = get_rest_time()
reps = get_reps()
return {'exercises': exercises,
'exercise_time': exercise_time,
'rest_time': rest_time,
'reps': reps}
def get_exercises(number_of_exercises: int = DEFAULT_EXERCISE_AMOUNT):
exercises = []
for i in range(number_of_exercises):
exercise = input(f'Exercise {i+1} of {number_of_exercises}: ')
exercises.append(exercise)
return exercises
def get_exercise_time():
ex_time = input(
f'Exercise Time in Seconds (Default is {DEFAULT_EXERCISE_TIME}): '
)
if ex_time == '':
return DEFAULT_EXERCISE_TIME
return int(ex_time)
def get_rest_time():
rest_time = input(
f'Rest Time in Seconds (Default is {DEFAULT_REST_TIME}): '
)
if rest_time == '':
return DEFAULT_REST_TIME
return int(rest_time)
def get_reps():
reps = input(
f'Circuit Repetitions (Default is {DEFAULT_REPETITIONS}): '
)
if reps == '':
return DEFAULT_REPETITIONS
return int(reps)
def get_current_time():
return round(time())
def start_period(name, length):
print(f'{Colors.WHITE}{name}{Colors.NORMAL}\n')
say(name)
countdown_timer(length)
def start_routine(exercises, exercise_time, rest_time, reps):
clear_screen()
start_period(f"Get ready! First is {exercises[0]}", 10)
for rep in range(reps):
for i, exercise in enumerate(exercises):
start_period(exercise, exercise_time)
clear_screen()
if rest_time != 0:
if i == len(exercises) - 1:
next_exercise = exercises[0]
else:
next_exercise = exercises[i+1]
if rep != reps-1 or i != len(exercises)-1:
start_period(f'Rest. Next is {next_exercise}', rest_time)
clear_screen()
say('Complete')
def say(msg: str):
os.system(f'say {msg} &')
def countdown_timer(period_time: int):
sleep(period_time-5)
for sec in range(5, 0, -1):
say(sec)
sleep(1)