-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (106 loc) · 4.33 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import click
from habit import HabitTracker, Habit
import questionary
from analytics import *
from db import HabitDB
tracker = HabitTracker()
@click.group()
def cli():
pass
@cli.command()
def create():
name = questionary.text("Enter the habit name: ").ask()
period = questionary.select("Enter the habit period:", choices=["daily", "weekly", "monthly"]).ask()
tracker.create_habit(name, period)
click.echo(f'Habit "{name}" with period "{period}" created successfully!')
@cli.command()
def delete():
name = questionary.text("Enter the habit name: ").ask()
tracker.delete_habit(name)
click.echo(f'Habit "{name}" deleted successfully!')
@cli.command()
def habit_groups():
habits = tracker.get_habits()
click.echo('Current habits:')
for habit in habits:
click.echo(f'- {habit.name} ({habit.period})')
@cli.command()
def habit_groups_period():
period = questionary.select("Enter the habit period:", choices=["daily", "weekly", "monthly"]).ask()
habits = tracker.get_habits_by_period(period)
click.echo(f'Current {period} habits:')
for habit in habits:
click.echo(f'- {habit.name}')
@cli.command()
def longest_streak():
longest_streak_habit = tracker.get_longest_streak()
if longest_streak_habit:
click.echo(f'Habit with longest streak: {longest_streak_habit.name} ({longest_streak_habit.get_streak()})')
else:
click.echo('No habits with a streak.')
@cli.command()
def longest_streak_habit():
name = questionary.text("Enter the habit name: ").ask()
streak = tracker.get_longest_streak_by_habit(name)
if streak:
click.echo(f'Longest streak for habit "{name}": {streak}')
else:
click.echo(f'Habit "{name}" not found.')
@cli.command()
def mark():
name = questionary.text("Enter the habit name: ").ask()
tracker.mark_complete(name)
click.echo(f'Habit "{name}" marked successfully!')
@cli.command()
def unmark():
name = questionary.text("Enter the habit name: ").ask()
tracker.mark_incomplete(name)
click.echo(f'Habit "{name}" unmarked successfully!')
def main():
while True:
command = input('Enter a command (create, delete, list, list-period, longest-streak, longest-streak-habit, or exit): ')
if command == 'create':
name = input('Enter the habit name: ')
period = input('Enter the habit period (daily or weekly): ')
tracker.create_habit(name, period)
click.echo(f'Habit "{name}" with period "{period}" created successfully!')
elif command == 'delete':
name = input('Enter the habit name: ')
tracker.delete_habit(name)
click.echo(f'Habit "{name}" deleted successfully!')
elif command == 'habit_groups':
habits = tracker.get_habits()
click.echo('Current habits:')
for habit in habits:
click.echo(f'- {habit.name} ({habit.period})')
elif command == 'habit_groups_period':
period = input('Enter the habit period (daily or weekly): ')
habits = tracker.get_habits_by_period(period)
click.echo(f'Current {period} habits:')
for habit in habits:
click.echo(f'- {habit.name}')
elif command == 'longest-streak':
longest_streak_habit = tracker.get_longest_streak()
if longest_streak_habit:
click.echo(f'Habit with longest streak: {longest_streak_habit.name} ({longest_streak_habit.get_streak()})')
else:
click.echo('No habits with a streak.')
elif command == 'longest-streak-habit':
name = input('Enter the habit name: ')
streak = tracker.get_longest_streak_by_habit(name)
if streak:
click.echo(f'Longest streak for habit "{name}": {streak}')
else:
click.echo(f'Habit "{name}" not found.')
elif command == 'mark':
name = input('Enter the habit name: ')
tracker.mark_complete(name)
click.echo(f'Habit "{name}" marked successfully!')
elif command == 'unmark':
name = input('Enter the habit name: ')
tracker.mark_incomplete(name)
click.echo(f'Habit "{name}" unmarked successfully!')
elif command == 'exit':
break
if __name__ == '__main__':
cli()