1
1
from argparse import Namespace
2
- from datetime import date
3
- from calendar import monthrange
4
-
5
- from tinydb import where
6
- from rich .pretty import pprint , Pretty
7
- from rich .console import Console , Group
2
+ from rich .pretty import pprint
8
3
from rich .panel import Panel
9
- from rich .progress import Progress , BarColumn , TaskProgressColumn , TextColumn , ProgressColumn
10
- from rich .rule import Rule
11
- from rich .table import Table
12
- from rich .text import Text
13
4
from rich import print
14
5
from rich .prompt import Prompt
15
6
16
7
from fob .db import TinyDBWrapper
17
8
from fob .db import checklist_complete
18
9
19
- # Custom Column to display assigned / total values
20
- class RawQuantityColumn (ProgressColumn ):
21
- def render (self , task ) -> Text :
22
- # Format as 'completed / total'
23
- completed_total = f"{ task .completed :.0f} / { task .total :.0f} "
24
- return Text (completed_total , style = "progress.data" )
25
-
26
10
def display_checklist (args : Namespace , db : TinyDBWrapper ) -> None :
27
11
try :
28
12
checklist = db .all ()[0 ]['checklist' ]
@@ -37,7 +21,6 @@ def display_checklist(args: Namespace, db: TinyDBWrapper) -> None:
37
21
for num , info in checklist .items ():
38
22
print (Panel (f"{ num } : { info ['name' ]} " , border_style = "bold green" if info ['done' ] else "bold red" ))
39
23
40
-
41
24
def day_checklist (args : Namespace , db : TinyDBWrapper ) -> None :
42
25
try :
43
26
try :
@@ -51,21 +34,17 @@ def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
51
34
pprint (checklist )
52
35
53
36
print ("[bold]\n Today's Checklist:[/bold]" )
54
- # create a new dict that creates an entry for each block
55
-
56
37
display_checklist (args , db )
57
38
58
39
if checklist_complete (db ):
59
40
print ("\n [green]All blocks have been completed![/green]" )
60
41
print ("Start a new day: [green bold]fob gm[/green bold]" )
61
42
return
62
43
else :
63
- # get user input
64
44
print ("\n [bold]Mark blocks as completed:[/bold]" )
65
45
check_number = Prompt .ask (f"Which blocks have you completed? (1-{ len (checklist )} ): " )
66
46
67
47
try :
68
- # mark the blocks as completed
69
48
checklist [check_number ].update ({"done" : True })
70
49
except KeyError :
71
50
print ("[red][bold]Invalid block number.[/red][/bold]" )
@@ -75,14 +54,12 @@ def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
75
54
print ("Updated checklist:" )
76
55
pprint (checklist )
77
56
78
- # update db
79
57
db .update ({"checklist" : checklist }, None )
80
58
81
59
if args .debug :
82
60
print ("Updated database:" )
83
61
pprint (db .all ())
84
62
85
- # updated checklist
86
63
print ("\n [green]Checklist updated![/green]\n " )
87
64
display_checklist (args , db )
88
65
@@ -91,55 +68,7 @@ def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
91
68
print ("Start a new day: [green bold]fob gm[/green bold]" )
92
69
return
93
70
94
- except KeyError as e : # No 'today' entry
71
+ except KeyError as e : # No 'today' entry
95
72
print ("[red][bold]No day data found.[/red][/bold]" )
96
73
if args .debug :
97
74
print (f"KeyError: { e } " )
98
-
99
-
100
-
101
- def month_overview (args : Namespace , db : TinyDBWrapper ) -> None :
102
- today = date .today ()
103
- try :
104
- data = db .search (where ('year' ) == today .year and where ('month' ) == today .month )[0 ]
105
- except IndexError :
106
- print ("[red][bold]No month data found.[/red][/bold]" )
107
- print ("Run [cyan][bold]fob new_month[/cyan][/bold] to start a new month." )
108
-
109
- return
110
-
111
- console = Console ()
112
-
113
- m_progress = Progress (
114
- TextColumn ("[progress.description]{task.description}" ),
115
- BarColumn (),
116
- TaskProgressColumn (),
117
- RawQuantityColumn (),
118
- disable = True
119
- )
120
-
121
- progress = Progress (
122
- TextColumn ("[progress.description]{task.description}" ),
123
- BarColumn (),
124
- TaskProgressColumn (),
125
- RawQuantityColumn (),
126
- disable = True # don't print immediately, print when called by console
127
- )
128
-
129
- today = date .today ()
130
- days_in_month = monthrange (today .year , today .month )[1 ]
131
-
132
- with m_progress :
133
- task = m_progress .add_task (f"Month" , total = days_in_month )
134
- m_progress .update (task , completed = today .day )
135
-
136
- task = m_progress .add_task (f"Work Days" , total = data ['work_days_allocated' ])
137
- m_progress .update (task , completed = data ['work_days_completed' ])
138
-
139
- with progress :
140
- for area_name , blocks in data ['areas' ].items ():
141
- task = progress .add_task (f"[bold]{ area_name } [/bold]" , total = blocks ['allocated' ])
142
- progress .update (task , completed = blocks ['completed' ])
143
-
144
- panel = Panel (Group (m_progress , Rule (style = 'cyan' ), progress ), title = "This Month" , border_style = "bold cyan" )
145
- console .print (panel )
0 commit comments