-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (74 loc) · 2.4 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
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
import typer
from myHabits import Habit
from db import get_db, create_table, insert_habit, show_habits, modify_habit, check_off_habit, check_habit_in_schedule, check_db_exists, del_habit
from analyse import get_all_habits_same_period, longest_streak, get_longest_streak_choose_habit, get_reason_and_failure_strategy
app = typer.Typer(add_completion=False, help="""
This is an App to track your Habits based on a fixed Schedule.\n
Keep in mind that you can cancel any process, that asks you for an input.\n
To do so, just type in 'CANCEL'. Enjoy!
""")
def habit_name_check(db, habit_name):
cur = db.cursor()
cur.execute('SELECT name FROM habits WHERE name =?', [habit_name])
return cur.fetchone() is not None
# Checks if the habit is already in the DB, before entering all other values.
@app.command()
def create_habit():
db = get_db()
create_table(db)
habit = Habit("", "", "", "", "", "", "", "", "")
habit.get_habit_name()
while habit_name_check(db, habit.name):
typer.echo("You already got that Habit in your List. Please choose another Habit, which you want to add.")
habit.get_habit_name()
habit.get_frequency()
habit.get_duration()
habit.get_habit_status()
habit.get_times()
insert_habit(db, habit.name, habit.frequency, habit.duration, habit.checked_status, habit.streak, habit.check_date,
habit.checked_timestamp)
typer.echo("Good Job, you added a new Habit!")
@app.command()
def show_all_habits():
db = get_db()
check_db_exists(db)
show_habits(db)
@app.command()
def edit_habit():
db = get_db()
check_db_exists(db)
modify_habit(db)
@app.command()
def delete_habit():
db = get_db()
check_db_exists(db)
del_habit(db)
@app.command()
def check_habit():
db = get_db()
check_db_exists(db)
check_off_habit(db)
@app.command()
def get_longest_streak():
db = get_db()
check_db_exists(db)
longest_streak(db)
@app.command()
def choose_habit_for_longest_streak():
db = get_db()
check_db_exists(db)
get_longest_streak_choose_habit(db)
@app.command()
def all_habits_same_period():
db = get_db()
check_db_exists(db)
get_all_habits_same_period(db)
@app.command()
def get_reason_and_strategy():
db = get_db()
check_db_exists(db)
show_habits(db)
get_reason_and_failure_strategy(db)
check_habit_in_schedule(get_db())
if __name__ == "__main__":
app()