-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (46 loc) · 1.85 KB
/
main.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
import os
import sqlite3
import questionary
from src.database.db import insert_initial_data
from src.habit import Habits
from utils.utils import handle_new_habit, handle_manage_habits, handle_analyse_habits, select_habit
# Message used in questionary call.
main_menu = {'msg': "What would you like to do ?",
'choices': ["Create a new habit",
"Check-off a habit",
"Manage tracked habits",
"Analyse your habits",
"Exit"]}
def cli():
"""
This function exposes a command line interface for the user to interact with the program.
It starts a loop and exits when the user chooses : 'Exit' in the main menu.
:return: None
"""
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "main.db")
if os.path.exists(path):
db = sqlite3.connect("main.db")
insert_initial_data(db)
questionary.print("\nWelcome to your Habit Tracking program.")
questionary.print("This program lets you define and manage your habits.\n", style="italic")
stop = False
else:
stop = True
print("The database does not exist. Please create it using the 'db_init.py' module.")
while not stop:
choice = questionary.select(main_menu['msg'], choices=main_menu['choices']).ask()
if choice == "Create a new habit":
handle_new_habit(db)
elif choice == "Check-off a habit":
selected_habit = select_habit(db)
habit = Habits(*selected_habit)
habit.complete_task(db)
elif choice == "Manage tracked habits":
handle_manage_habits(db)
elif choice == "Analyse your habits":
handle_analyse_habits(db)
else:
print("See you again !")
stop = True
if __name__ == "__main__":
cli()