-
Notifications
You must be signed in to change notification settings - Fork 2
/
4-finish.py
executable file
·74 lines (65 loc) · 2.26 KB
/
4-finish.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
#!/usr/bin/python3
from os.path import exists
import datetime
import termcolor
path="log/"
file="day.csv"
# Create file, if necessary
if not exists(path + file):
print("Daily log not found. Creating...")
stream = open(path + file, "xt")
# Reading content
stream = open(path + file, "rt")
print("Date\t\tUpper\tAbs\tLower\tCardio")
streak_upper = []
streak_abs = []
streak_lower = []
streak_cardio = []
for line in stream: # TODO: DRY (same code in Exercise class)
line_split = line.split(",")
streak_upper.append(line_split[1] == 'True')
streak_abs.append(line_split[2] == 'True')
streak_lower.append(line_split[3] == 'True')
streak_cardio.append(line_split[4] == 'True\n')
# Runtime coloring of True and False
for l in range(len(line_split)):
if line_split[l] in ["True", "True\n"]:
line_split[l] = termcolor.colored("True", "green")
elif line_split[l] in ["False", "False\n"]:
line_split[l] = termcolor.colored("False", "red")
line_string = '\t'.join(line_split).replace("\n","")
print(line_string)
stream.close()
def calcStreak(x):
x.reverse()
done_streak = 0
for element in x:
if element:
done_streak += 1
if not element:
break
rest_streak = 0
for element in x:
if not element:
rest_streak +=1
else:
break
return([done_streak, rest_streak])
print('Upper streak [done, rest]: ' + str(calcStreak(streak_upper)))
print('Abs streak [done, rest]: ' + str(calcStreak(streak_abs)))
print('Lower streak [done, rest]: ' + str(calcStreak(streak_lower)))
print('Cardio streak [done, rest]: ' + str(calcStreak(streak_cardio)))
# Reading new content
today = datetime.datetime.now().strftime("%Y-%m-%d")
date = input("Enter date (if different from " + today +"): ") # TODO: DRY (same code in Exercise class)
if date == "":
date = today
did_upper = input("Worked upper body [y/N]? ") != "n"
did_abs = input("Worked abs [y/N]? ") != "n"
did_lower = input("Worked lower body [y/N]? ") != "n"
did_cardio = input("Did cardio [y/N]? ") != "n"
# Saving data
stream = open(path + file, "at")
new_line = ','.join([str(date), str(did_upper), str(did_abs), str(did_lower), str(did_cardio)]) + "\n"
stream.write(new_line)
stream.close()