-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper_functions.py
More file actions
143 lines (119 loc) · 3.56 KB
/
wrapper_functions.py
File metadata and controls
143 lines (119 loc) · 3.56 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
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
import db.db_operations as db
import c_logging.logger as log
from db.tools import get_new_habit, Commands, set_test_mode
import db.tools as tools
import exceptions.exceptions as exceptions
from pandas import DataFrame
def quick_test():
# add()
# print(db.get_habit_by_title('mama'))
pass
################################ Main wrappers ################################
def welcome():
print("Welcome to your personal habit tracker")
def initialize_logger():
log.start_logger()
log.set_level_debug()
def initialize_db():
db.create_tables()
def close_app():
exit(0)
def reset():
"""Removes database and initializes it again"""
initialize()
clear_storage()
initialize()
def clear_storage():
db.drop_db()
def initialize():
try:
initialize_logger()
initialize_db()
except Exception as e:
print(e)
close_app()
def initialize_for_testing():
try:
set_test_mode()
initialize_db()
clear_storage()
initialize_logger()
initialize_db()
except Exception as e:
print(e)
close_app()
################################ Commands wrappers ################################
def add():
"""a function to add a new habit"""
# ask the user to insert values
new_habit = get_new_habit()
try:
db.add_habit(new_habit)
except exceptions.DuplicateHabit as e:
print(e)
except Exception as e:
print(e)
close_app()
def help():
"""Prints all the possible commands with their usage"""
print()
for command_usage in Commands.get_commands().values():
print(command_usage + "\n")
def ask():
"""
Will ask the user about each habit if he completed yesterday,
if he already answered those or there are no habits => tell the user
"""
# get habits
# if no habits print
# get rows in the table named tracker with yesterday's date
# if there are rows ? in the last query =? ask about the habkits that are not there
try:
print(DataFrame(db.get_all_habits()))
except Exception as e:
print(e)
close_app()
def progress(month: int, year: int):
"""Prints the progress of all habits for the specified month"""
pass
def habits():
[print(habit) for habit in db.get_all_habits()]
################################ Command handlers ################################
def get_command() -> str:
"""must be one of predefined commands, otherwise ask again"""
command = input(">>> ").strip()
while len(command) == 0:
command = input("\n>>> ")
main_command = command.split()[0]
while main_command not in Commands.get_commands().keys():
print("Command not found. Use the command 'help' to see possible Commands.\n")
command = input(">>> ").strip()
while len(command) == 0:
command = input("\n>>> ")
main_command = command.split()[0]
return command
def execute_command(command: str):
"""
parameters:
command: a string containing the whole command
"""
if command == Commands.ADD.value:
add()
elif command == Commands.TRACK.value:
pass
elif command == Commands.ARCHIVE.value:
pass
elif command == Commands.DELETE.value:
pass
elif command == Commands.HABITS.value:
habits()
elif command == Commands.HELP.value:
help()
elif command == Commands.PROGRESS.value:
pass
elif command == Commands.UPDATE.value:
pass
elif command == Commands.EXIT.value:
close_app()
else:
return