-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasker.py
693 lines (508 loc) · 25.4 KB
/
tasker.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
import csv
import os
import time
from datetime import datetime, timedelta
from click import echo
from colorama import Fore, init
from prettytable import ALL as ALL
from prettytable import PrettyTable
from prompt_toolkit import PromptSession, prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit.history import FileHistory
from prompt_toolkit.styles import Style
from tinydb import Query, TinyDB, where
from tinydb.operations import delete
from art import text2art
style = Style.from_dict({
'': 'gold'
})
prompt_symbol = FormattedText([
('gold bold', '<< tasker >> ')
])
dirname = os.path.dirname(__file__)
datafile = os.path.join(dirname, 'db.json')
db = TinyDB(datafile)
task_table = db.table('tasks')
project_table = db.table('projects')
name_table = db.table('names')
number_of_concurrent_tasks = 3
max_line_length = 25
project_list = []
format_date_str = "%A, %d %b %Y %I:%M:%S %p"
format_delta_str_hours = "%d days %H:%M:%S"
# format_delta_str_days = "%d days %H:%M:%S"
filename_format = '%Y-%m-%d %I%M-%p'
zero_delta = '0 days 0:00:00'
task_table_columns = ["Task Name",
"Project Name",
"Start Date",
"End Date",
"Last Restart Date",
"Last Paused Date",
"Paused",
"Duration"]
command_list = ['add_running_task',
'add_paused_task',
'delete_task',
'end_task',
'list_pending_tasks',
'list_all_tasks',
'pause_task',
'start_paused_task',
'update_task_name',
'exit',
'export_completed_tasks',
'pause_all_tasks',
'delete_completed_tasks',
'complete_task_manually',
'update_project_name']
sorted_commands = sorted(command_list, key=str.lower)
def convert_to_timedelta(value):
value = str(value)
if 'days' in value:
days_v_hms = value.split('days')
hms = days_v_hms[1].split(':')
dt = timedelta(days=int(days_v_hms[0]), hours=int(hms[0]), minutes=int(hms[1]), seconds=float(hms[2]))
elif 'day' in value:
days_v_hms = value.split('day')
hms = days_v_hms[1].split(':')
dt = timedelta(days=int(days_v_hms[0]), hours=int(hms[0]), minutes=int(hms[1]), seconds=float(hms[2]))
else:
hms = value.split(':')
dt = timedelta(hours=int(hms[0]), minutes=int(hms[1]), seconds=float(hms[2]))
return(dt)
def get_running_duration(restart_datetime, current_duration, is_paused, is_ended):
if (is_paused == False) and (is_ended.strip() == ''):
current_time = get_timestamp()
formatted_current_time = datetime.strptime(current_time, format_date_str)
formatted_start_date = datetime.strptime(restart_datetime.strip(), format_date_str)
dt = convert_to_timedelta(current_duration)
diff = formatted_current_time - formatted_start_date
paused_duration = str(dt + diff)
return(paused_duration)
else:
return(current_duration)
def get_timestamp(format = format_date_str):
result = datetime.now().strftime(format)
return result
def check_date_format(date_to_test):
try:
datetime.strptime(date_to_test,format_date_str)
except:
return(f'{date_to_test} is not the right format. The format should be {format_date_str}')
def check_delta_format(delta_to_test):
try:
convert_to_timedelta(delta_to_test)
except ValueError as error:
return(str(error)) #f'{delta_to_test} is not the right format. The format should be {format_delta_str_hours}')
def select_column(input_list, column1, column2=''):
if column2 == '':
return [dict_row[column1] for dict_row in input_list]
elif column2 != '':
out = []
for dict_row in input_list:
c1 = dict_row[column1]
c2 = dict_row[column2]
row = f'{c1} - {c2}'
out.append(row)
return(out)
def to_csv(data_list, name):
output_task_table(data_list, task_table_columns)
current_time = get_timestamp(filename_format)
keys = data_list[0].keys()
with open(f'{name} - Completed Tasks {current_time}.csv', 'a', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys)
dict_writer.writeheader()
dict_writer.writerows(data_list)
def format_column_value(line, max_line_length):
ACC_length = 0
if '\n' not in line:
words = line.split(" ")
formatted_line = ""
for word in words:
if ACC_length + (len(word) + 1) <= max_line_length:
formatted_line = formatted_line + word + " "
ACC_length = ACC_length + len(word) + 1
else:
formatted_line = formatted_line + "\n" + word + " "
ACC_length = len(word) + 1
return(formatted_line)
else:
return(line.strip())
def output_task_table(dict_list, columns):
cli_table = PrettyTable(hrules=ALL)
cli_table.field_names = columns
for task in dict_list:
for column in columns:
column = column.lower().replace(" ", "_")
if type(task[column]) != bool:
task[column] = format_column_value(task[column], max_line_length).strip()
running_duration = get_running_duration(task['last_restart_date'], task['duration'], task['paused'], task['end_date'])
cli_table.add_row([
task['task_name'],
task['project_name'],
task['start_date'], task['end_date'],
task['last_restart_date'],
task['last_paused_date'],
task['paused'],
running_duration])
echo(cli_table)
def custom_print_green(value):
return(echo(Fore.GREEN + value))
def custom_print_blue(value):
return(echo(Fore.BLUE + value))
def custom_print_red(value):
return(echo(Fore.RED + value))
command_completer = WordCompleter(
sorted_commands,
ignore_case=True)
custom_print_blue(text2art('<< tasker >>'))
custom_print_blue('''
tasker is a simple tool to track your daily/weekly tasks and export them as needed.
You can add running tasks and start tracking the time right away or add paused tasks you can start later.
Simply add a task and what project it belongs to. tasker will add it to your task list.
Pause a task, or all tasks, and restar them later. tasker will aggregate total duration.
End the task completely to let tasker know you are done with the task and it is ready to be exported.
Press TAB to and scroll through to see the list of commands.
''')
while 1:
user_input = prompt(prompt_symbol, completer=command_completer, wrap_lines=False, complete_while_typing=True, style=style)
if user_input == 'exit':
if os.path.exists('history.txt'):
os.remove('history.txt')
custom_print_green('Goodbye.')
break
elif user_input == 'add_running_task':
project_list = select_column(project_table.all(), 'project_name')
project_command_completer = WordCompleter(project_list, ignore_case=True)
task_session = PromptSession()
task_name = task_session.prompt(
'Name: '
)
task_project = task_session.prompt(
'Project: ',
completer=project_command_completer,
wrap_lines=False,
complete_while_typing=True
)
if task_name == '' or task_project == '':
custom_print_red('The Task and/or Project cannot be blank.')
else:
start_time = get_timestamp()
existing_task_names = select_column(task_table.search(where('project_name') == task_project), 'task_name')
running_tasks = select_column(task_table.search((where('end_date') == '') & (where('paused') == False)), 'task_name')
if task_name not in existing_task_names:
if len(running_tasks) < number_of_concurrent_tasks:
task_table.insert({'task_name': task_name, 'project_name': task_project, 'start_date': start_time, 'end_date': '',
'last_restart_date': start_time, 'last_paused_date': '', 'paused': False, 'duration': zero_delta})
custom_print_green(f'Task: "{task_name}" successfully started. Time: {start_time}')
if task_project not in project_list:
project_table.insert({'project_name': task_project, 'created_on': start_time})
else:
custom_print_red('You can only have a maximum of 3 running tasks at any time. Please Pause or End existing running Tasks.')
else:
custom_print_red('That Task name already exists for that project. Please choose a different Task name')
elif user_input == 'add_paused_task':
project_list = select_column(project_table.all(), 'project_name')
project_command_completer = WordCompleter(project_list, ignore_case=True)
task_session = PromptSession()
task_name = task_session.prompt(
'Name: '
)
task_project = task_session.prompt(
'Project: ',
completer=project_command_completer,
wrap_lines=False,
complete_while_typing=True
)
if task_name == '' or task_project == '':
custom_print_red('The Task and/or Project cannot be blank.')
else:
start_time = get_timestamp()
existing_task_names = select_column(task_table.search(where('project_name') == task_project), 'task_name')
if task_name not in existing_task_names:
task_table.insert({'task_name': task_name, 'project_name': task_project, 'start_date': start_time, 'end_date': '',
'last_restart_date': start_time, 'last_paused_date': start_time, 'paused': True, 'duration': zero_delta})
if task_project not in project_list:
project_table.insert({'project_name': task_project, 'created_on': start_time})
custom_print_green(f'Task: "{task_name}" successfully started. Time: {start_time}')
else:
custom_print_red('That Task name already exists for that project. Please choose a different Task name')
elif user_input == 'end_task':
task_list = select_column(task_table.search(where('end_date') == ''), 'task_name', 'project_name')
task_command_completer = WordCompleter(task_list, ignore_case=True)
task_session = PromptSession()
task_to_end = task_session.prompt('Select Started Task to End: ', completer = task_command_completer, wrap_lines=False,
complete_while_typing=True)
if task_to_end in task_list:
current_task_project = task_to_end.split(' - ')[1]
task_to_end = task_to_end.split(' - ')[0]
current_time = get_timestamp()
task_list = select_column(task_table.search(where('end_date') == ''), 'task_name')
paused_tasks = select_column(task_table.search((where('paused') == True) & (where('project_name') == current_task_project)), 'task_name')
current_start_time = select_column(task_table.search(where('task_name') == task_to_end), 'last_restart_date')[0]
current_duration = select_column(task_table.search((where('task_name') == task_to_end) & (where('project_name') == current_task_project)), 'duration')[0]
formatted_current_time = datetime.strptime(current_time, format_date_str)
formatted_start_date = datetime.strptime(current_start_time, format_date_str)
dt = convert_to_timedelta(current_duration)
diff = formatted_current_time - formatted_start_date
total_duration = str(dt + diff)
if task_to_end not in paused_tasks:
task_table.update({'duration': total_duration, 'end_date': current_time, 'paused': False}, (where('task_name') == task_to_end) & (where('project_name') == current_task_project))
custom_print_green(f'Task: "{task_to_end}" successfully ended. Time: {current_time}')
else:
if current_duration != zero_delta:
task_table.update({'end_date': current_time, 'paused': False}, (where('task_name') == task_to_end) & (where('project_name') == current_task_project))
custom_print_green(f'Task: "{task_to_end}" successfully ended. Time: {current_time}')
else:
custom_print_red('Cannot end Task because it is paused and the duration is 0 days 0:00:00')
else:
custom_print_red('That Task does not exist or has ended, please try again.')
elif user_input == 'delete_task':
task_list = select_column(task_table.all(), 'task_name', 'project_name')
task_command_completer = WordCompleter(task_list, ignore_case=True)
task_session = PromptSession()
task_to_delete = task_session.prompt(
'Select Task to Delete: ',
completer = task_command_completer,
wrap_lines=False,
complete_while_typing=True
)
if task_to_delete in task_list:
task_list = select_column(task_table.all(), 'task_name')
current_task_project = task_to_delete.split(' - ')[1]
task_to_delete = task_to_delete.split(' - ')[0]
confirm = task_session.prompt(f'Are you sure you want to delete "{task_to_delete}" (y/n): ')
if confirm == 'y':
task_table.remove((where('task_name') == task_to_delete) & (where('project_name') == current_task_project) )
custom_print_green(f'Task: "{task_to_delete}" successfully deleted.')
project_list = select_column(task_table.search(where('project_name') == current_task_project), 'project_name')
if len(project_list) == 0:
project_table.remove((where('project_name') == current_task_project) )
elif confirm == 'n':
custom_print_green('Deletion cancelled.')
else:
custom_print_red('Did not understand answer to confirmation. Please try again.')
else:
custom_print_red('That Task does not exist, please try again.')
elif user_input == 'list_pending_tasks':
pending_tasks = task_table.search(where('end_date') == '')
if len(pending_tasks) > 0:
output_task_table(pending_tasks, task_table_columns)
else:
custom_print_red('There are no pending Tasks.')
elif user_input == 'list_all_tasks':
all_tasks = task_table.all()
if len(all_tasks) > 0:
output_task_table(all_tasks, task_table_columns)
else:
custom_print_red('No Tasks have been added yet.')
elif user_input == 'pause_task':
task_list = select_column(task_table.search((where('end_date') == '') & (where('paused') == False)), 'task_name', 'project_name')
task_command_completer = WordCompleter(task_list, ignore_case=True)
task_session = PromptSession()
task_to_pause = task_session.prompt(
'Select Started Task to Pause: ',
completer = task_command_completer,
wrap_lines=False,
complete_while_typing=True
)
if task_to_pause in task_list:
current_time = get_timestamp()
current_task_project = task_to_pause.split(' - ')[1]
task_to_pause = task_to_pause.split(' - ')[0]
task_list = select_column(task_table.search((where('end_date') == '') & (where('paused') == False)), 'task_name')
current_start_time = select_column(task_table.search((where('task_name') == task_to_pause) & (where('project_name') == current_task_project)), 'last_restart_date')[0]
current_duration = select_column(task_table.search((where('task_name') == task_to_pause) & (where('project_name') == current_task_project)), 'duration')[0]
formatted_current_time = datetime.strptime(current_time, format_date_str)
formatted_start_date = datetime.strptime(current_start_time, format_date_str)
dt = convert_to_timedelta(current_duration)
diff = formatted_current_time - formatted_start_date
paused_duration = str(dt + diff)
task_table.update({'duration': paused_duration, 'last_paused_date': current_time, 'paused': True}, (where('task_name') == task_to_pause) & (where('project_name') == current_task_project))
custom_print_green(f'Task: "{task_to_pause}" successfully paused. Time: {current_time}')
else:
custom_print_red('That Task does not exist or is already Paused, please try again.')
elif user_input == 'start_paused_task':
task_list = select_column(task_table.search((where('end_date') == '') & (where('paused') == True)), 'task_name', 'project_name')
task_command_completer = WordCompleter(task_list, ignore_case=True)
task_session = PromptSession()
task_to_restart = task_session.prompt(
'Select Paused Task to Restart: ',
completer = task_command_completer,
wrap_lines=False,
complete_while_typing=True
)
if task_to_restart in task_list:
current_task_project = task_to_restart.split(' - ')[1]
task_to_restart = task_to_restart.split(' - ')[0]
current_time = get_timestamp()
task_list = select_column(task_table.search((where('end_date') == '') & (where('paused') == True)), 'task_name')
running_tasks = select_column(task_table.search((where('end_date') == '') & (where('paused') == False)), 'task_name')
is_ended = select_column(task_table.search((where('task_name') == task_to_restart) & (where('project_name') == current_task_project)), 'end_date')[0]
if is_ended == '':
if len(running_tasks) < number_of_concurrent_tasks:
task_table.update({'last_restart_date': current_time, 'paused': False}, (where('task_name') == task_to_restart) & (where('project_name') == current_task_project))
custom_print_green(f'Task: "{task_to_restart}" successfully restarted. Time: {current_time}')
else:
custom_print_red('You can only have a maximum of 3 running tasks at any time. Please Pause or End existing running Tasks.')
else:
custom_print_red('The Task has ended. Please create a new Task.')
else:
custom_print_red('That Task does not exist or is not Paused, please try again.')
elif user_input == 'update_task_name':
task_list = select_column(task_table.all(), 'task_name', 'project_name')
task_command_completer = WordCompleter(task_list, ignore_case=True)
task_session = PromptSession()
task_to_update_name = task_session.prompt(
'Select Task to Update: ',
completer = task_command_completer,
wrap_lines=False,
complete_while_typing=True
)
name_to_update_to = task_session.prompt(
'Update the Task Name: ',
completer = task_command_completer,
wrap_lines=False,
complete_while_typing=True,
default = task_to_update_name.split(' - ')[0]
).split(' - ')[0]
if task_to_update_name in task_list:
task_list = select_column(task_table.all(), 'task_name')
current_task_project = task_to_update_name.split(' - ')[1]
task_to_update_name = task_to_update_name.split(' - ')[0]
existing_task_names = select_column(task_table.search(where('project_name') == current_task_project), 'task_name')
if name_to_update_to not in existing_task_names:
task_table.update({'task_name': name_to_update_to}, (where('task_name') == task_to_update_name) & (where('project_name') == current_task_project))
custom_print_green(f'Task "{task_to_update_name}" has been updated to "{name_to_update_to}"')
else:
custom_print_red(f'The Task name {name_to_update_to} already exists for the project {current_task_project}. Please choose a different Task name.')
else:
custom_print_red('That Task does not exist, please try again.')
elif user_input == 'export_completed_tasks':
completed_tasks = task_table.search(where('end_date') != '')
task_session = PromptSession()
name_list = select_column(name_table.all(), 'name')
name_command_completer = WordCompleter(name_list, ignore_case=True)
if len(completed_tasks) > 0:
name = task_session.prompt('Your Name (Please be consistent with previous exports): ', completer=name_command_completer,)
to_csv(completed_tasks, name)
custom_print_green('Completed Tasks exported.')
if name not in name_list:
name_table.insert({'name': name, 'created_on': get_timestamp()})
else:
custom_print_red('There were not completed Tasks to export.')
elif user_input == 'pause_all_tasks':
task_list = select_column(task_table.search((where('end_date') == '') & (where('paused') == False)), 'task_name', 'project_name')
if len(task_list) > 0:
for task_to_pause in task_list:
current_time = get_timestamp()
current_task_project = task_to_pause.split(' - ')[1]
task_to_pause = task_to_pause.split(' - ')[0]
current_start_time = select_column(task_table.search(where('task_name') == task_to_pause), 'last_restart_date')[0]
current_duration = select_column(task_table.search(where('task_name') == task_to_pause), 'duration')[0]
formatted_current_time = datetime.strptime(current_time, format_date_str)
formatted_start_date = datetime.strptime(current_start_time, format_date_str)
dt = convert_to_timedelta(current_duration)
diff = formatted_current_time - formatted_start_date
paused_duration = str(dt + diff)
task_table.update({'duration': paused_duration, 'last_paused_date': current_time, 'paused': True}, (where('task_name') == task_to_pause) & (where('project_name') == current_task_project))
custom_print_green(f'Task: "{task_to_pause}" successfully paused. Time: {current_time}')
else:
custom_print_red('There are no running Tasks to Pause.')
elif user_input == 'delete_completed_tasks':
task_list = select_column(task_table.search((where('end_date') != '') & (where('paused') == False)), 'task_name', 'project_name')
completed_tasks = task_table.search(where('end_date') != '')
if len(task_list) > 0:
task_session = PromptSession()
confirm = task_session.prompt(f'Are you sure you want to delete all tasks? You will be forced to export before deleting. (y/n): ')
if confirm == 'y':
name_list = select_column(name_table.all(), 'name')
name_command_completer = WordCompleter(name_list, ignore_case=True)
if len(completed_tasks) > 0:
name = task_session.prompt('Your Name (Please be consistent with previous exports): ', completer=name_command_completer,)
to_csv(completed_tasks, name)
custom_print_green('Completed Tasks exported.')
if name not in name_list:
name_table.insert({'name': name, 'created_on': get_timestamp()})
else:
custom_print_red('There were not completed Tasks to export.')
for task_to_delete in task_list:
current_task_project = task_to_delete.split(' - ')[1]
task_to_delete = task_to_delete.split(' - ')[0]
task_table.remove((where('task_name') == task_to_delete) & (where('project_name') == current_task_project) )
custom_print_green(f'Task: "{task_to_delete}" successfully deleted.')
elif confirm == 'n':
custom_print_red('Deletion cancelled.')
else:
custom_print_red('Did not understand answer to confirmation. Please try again.')
else:
custom_print_red('There are no completed tasks to remove.')
elif user_input == 'complete_task_manually':
task_list = select_column(task_table.search(where('end_date') == ''), 'task_name', 'project_name')
task_command_completer = WordCompleter(task_list, ignore_case=True)
task_session = PromptSession()
task_to_complete = task_session.prompt('Select Started Task to Complete: ',
completer = task_command_completer,
wrap_lines=False,
complete_while_typing=True)
if task_to_complete in task_list:
current_time = get_timestamp()
current_task_project = task_to_complete.split(' - ')[1]
task_to_complete = task_to_complete.split(' - ')[0]
start_time = select_column(task_table.search((where('task_name') == task_to_complete) & (where('project_name') == current_task_project)), 'start_date')[0]
task_list = select_column(task_table.search(where('end_date') == ''), 'task_name')
paused_tasks = select_column(task_table.search((where('paused') == True) & (where('project_name') == current_task_project)), 'task_name')
current_duration = select_column(task_table.search((where('task_name') == task_to_complete) & (where('project_name') == current_task_project)), 'duration')[0]
if task_to_complete in paused_tasks:
start_time = task_session.prompt('Do you want to update the start time? (Press ENTER for default) ', wrap_lines=False, default=str(start_time))
end_time = task_session.prompt('When was the Task completed? (Press ENTER for default) ', wrap_lines=False, default=str(current_time))
task_duration = task_session.prompt('How long did it take to complete? ', wrap_lines=False, default=zero_delta)
start_time_check = check_date_format(start_time)
end_time_check = check_date_format(end_time)
task_duration_check = check_delta_format(task_duration)
if (start_time_check == None) and (end_time_check == None) and (task_duration_check == None):
if task_duration != zero_delta:
task_table.update({'start_date': start_time,'duration': task_duration, 'end_date': end_time, 'paused': False}, (where('task_name') == task_to_complete) & (where('project_name') == current_task_project))
custom_print_green(f'Task: "{task_to_complete}" successfully completed. Time: {end_time}')
else:
custom_print_red('The duration cannot be 0 days 0:00:00.')
else:
if start_time_check != None:
custom_print_red(start_time_check)
if end_time_check != None:
custom_print_red(end_time_check)
if task_duration_check != None:
custom_print_red(task_duration_check)
else:
custom_print_red('This Task is currently not paused. Please pause the Task first to complete manually.')
else:
custom_print_red('That Task does not exist or has been completed, please try again.')
elif user_input == 'update_project_name':
project_list = select_column(project_table.all(), 'project_name')
project_command_completer = WordCompleter(project_list, ignore_case=True)
task_session = PromptSession()
project_name_to_update = task_session.prompt(
'Select Project Name to Update: ',
completer = project_command_completer,
wrap_lines = False,
complete_while_typing=True
)
if project_name_to_update in project_list:
project_name_to_update_to = task_session.prompt(
'Update the Project Name: ',
completer = project_command_completer,
wrap_lines=False,
complete_while_typing=True,
default = project_name_to_update
)
task_list = select_column(task_table.search(where('project_name') == project_name_to_update), 'task_name')
for task in task_list:
task_table.update({'project_name': project_name_to_update_to}, (where('task_name') == task) & (where('project_name') == project_name_to_update))
project_table.update({'project_name': project_name_to_update_to}, where('project_name') == project_name_to_update)
custom_print_green(f'Project "{project_name_to_update}" has been successfully updated to "{project_name_to_update_to}"')
else:
custom_print_red('That Project does not exist, please try again.')
else:
custom_print_red('Not a valid command. Press TAB to view list of possible commands.')