-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py.bak
More file actions
866 lines (736 loc) · 29.3 KB
/
main.py.bak
File metadata and controls
866 lines (736 loc) · 29.3 KB
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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
from fastapi import FastAPI, Form, HTTPException, Request
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from pydantic import BaseModel
from datetime import datetime
from typing import List, Optional
import json
import os
from threading import Lock
# JSON file paths
TODO_FILE = "TodoTasks.json"
DONE_FILE = "DoneTodo.json"
# Thread lock for file operations
file_lock = Lock()
app = FastAPI()
# Mount static files and templates
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
# Pydantic models
class TaskCreate(BaseModel):
task_name: str
amount: float
time_from: Optional[str] = None
time_to: Optional[str] = None
class Task(BaseModel):
id: int
task_name: str
amount: float
created_at: str
date: str # Date in YYYY-MM-DD format for filtering
time_from: Optional[str] = None
time_to: Optional[str] = None
class DoneTask(BaseModel):
id: int
task_name: str
amount: float
created_at: str
completed_at: str
date: str
time_from: Optional[str] = None
time_to: Optional[str] = None
# Helper functions
def load_json_file(filepath: str) -> List:
"""Load JSON file, return empty list if not exists"""
if not os.path.exists(filepath):
return []
try:
with open(filepath, 'r') as f:
return json.load(f)
except:
return []
def save_json_file(filepath: str, data: List):
"""Save data to JSON file"""
with open(filepath, 'w') as f:
json.dump(data, f, indent=2)
def get_next_id(tasks: List) -> int:
"""Get next available ID"""
if not tasks:
return 1
return max(task['id'] for task in tasks) + 1
def get_today_date() -> str:
"""Get today's date in YYYY-MM-DD format"""
return datetime.now().strftime("%Y-%m-%d")
def get_running_total() -> float:
"""Calculate running total from completed tasks"""
with file_lock:
done_tasks = load_json_file(DONE_FILE)
return sum(task['amount'] for task in done_tasks)
def get_render_data():
"""Get data for rendering the page"""
with file_lock:
todo_tasks = load_json_file(TODO_FILE)
done_tasks = load_json_file(DONE_FILE)
running_total = sum(task['amount'] for task in done_tasks)
today = get_today_date()
# Filter tasks for today
today_tasks = [t for t in todo_tasks if t['date'] == today]
# Create a set of done task IDs for quick lookup
done_task_ids = {t['id'] for t in done_tasks}
# Regular tasks list
tasks_html = ""
for task in today_tasks:
is_done = task['id'] in done_task_ids
checked = "checked" if is_done else ""
task_class = "done" if is_done else ""
created_dt = datetime.fromisoformat(task['created_at'])
created_date = created_dt.strftime("%m/%d %I:%M%p")
completed_date = ""
if is_done:
done_task = next((t for t in done_tasks if t['id'] == task['id']), None)
if done_task:
completed_dt = datetime.fromisoformat(done_task['completed_at'])
completed_date = completed_dt.strftime("%m/%d %I:%M%p")
tasks_html += f"""
<div class="task-item {task_class}">
<div class="task-left">
<input type="checkbox" class="task-checkbox" data-id="{task['id']}" {checked}>
<div class="task-info">
<div class="task-name">{task['task_name']}</div>
<div class="task-date">Created: {created_date}{f" | Done: {completed_date}" if completed_date else ""}</div>
</div>
</div>
<div class="task-right">
<div class="task-amount">₹{task['amount']:.2f}</div>
<button class="delete-btn" data-id="{task['id']}">🗑️</button>
</div>
</div>
"""
# Timebox tasks (sorted by time)
timed_tasks = [t for t in today_tasks if t.get('time_from')]
timed_tasks.sort(key=lambda x: x.get('time_from', ''))
timebox_html = ""
for task in timed_tasks:
is_done = task['id'] in done_task_ids
task_class = "done" if is_done else ""
time_range = f"{task.get('time_from', '')} - {task.get('time_to', '')}"
timebox_html += f"""
<div class="timebox-item {task_class}">
<div class="timebox-time">{time_range}</div>
<div class="timebox-task-name">{task['task_name']}</div>
<div class="timebox-amount">₹{task['amount']:.2f}</div>
<div class="timebox-actions">
<input type="checkbox" class="task-checkbox" data-id="{task['id']}" {'checked' if is_done else ''}>
<button class="delete-btn-small" data-id="{task['id']}">🗑️</button>
</div>
</div>
"""
return {
"tasks_html": tasks_html,
"timebox_html": timebox_html,
"running_total": running_total
}
# Routes
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
data = get_render_data()
return templates.TemplateResponse("index.html", {
"request": request,
**data
})
@app.post("/api/tasks")
padding: 0;
box-sizing: border-box;
}}
body {{
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #9b59b6 0%, #6c3483 100%);
min-height: 100vh;
padding: 20px;
display: flex;
gap: 20px;
}}
.timebox-container {{
width: 350px;
background: white;
border-radius: 20px;
box-shadow: 0 10px 40px rgba(107, 52, 131, 0.3);
overflow: hidden;
height: fit-content;
max-height: calc(100vh - 40px);
display: flex;
flex-direction: column;
}}
.container {{
flex: 1;
background: white;
border-radius: 20px;
box-shadow: 0 10px 40px rgba(107, 52, 131, 0.3);
overflow: hidden;
max-height: calc(100vh - 40px);
display: flex;
flex-direction: column;
}}
.header {{
background: linear-gradient(135deg, #8e44ad 0%, #6c3483 100%);
color: white;
padding: 30px;
text-align: center;
}}
h1 {{
font-size: 2.5em;
font-weight: 700;
}}
.total-section {{
background: #7d3c98;
color: white;
padding: 20px 30px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 3px solid #6c3483;
}}
.total-label {{
font-size: 1.2em;
font-weight: 500;
}}
.total-amount {{
font-size: 2em;
font-weight: 700;
}}
.add-task-section {{
padding: 30px;
background: #f9f9f9;
border-bottom: 2px solid #e8e8e8;
}}
.form-row {{
display: flex;
gap: 15px;
margin-bottom: 15px;
}}
.time-inputs {{
display: flex;
gap: 10px;
align-items: center;
padding: 10px;
background: white;
border: 2px solid #d4b8e8;
border-radius: 10px;
margin-bottom: 15px;
}}
.time-label {{
font-size: 0.9em;
color: #666;
font-weight: 500;
}}
input[type="text"],
input[type="number"] {{
flex: 1;
padding: 12px 15px;
border: 2px solid #d4b8e8;
border-radius: 10px;
font-size: 1em;
font-family: 'Inter', sans-serif;
background: white;
transition: border-color 0.3s;
}}
select {{
padding: 8px 10px;
border: 2px solid #d4b8e8;
border-radius: 10px;
font-size: 1em;
font-family: 'Inter', sans-serif;
background: white;
cursor: pointer;
transition: border-color 0.3s;
}}
select:focus {{
outline: none;
border-color: #8e44ad;
}}
.time-group {{
display: flex;
gap: 5px;
align-items: center;
}}
input[type="text"]:focus,
input[type="number"]:focus {{
outline: none;
border-color: #8e44ad;
}}
.add-btn {{
width: 100%;
padding: 12px;
background: linear-gradient(135deg, #8e44ad 0%, #6c3483 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 1.1em;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}}
.add-btn:hover {{
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(142, 68, 173, 0.4);
}}
.add-btn:active {{
transform: translateY(0);
}}
.tasks-section {{
padding: 20px 30px;
overflow-y: auto;
flex: 1;
}}
.timebox-section {{
padding: 20px;
overflow-y: auto;
flex: 1;
}}
.timebox-header {{
background: linear-gradient(135deg, #8e44ad 0%, #6c3483 100%);
color: white;
padding: 20px;
text-align: center;
font-size: 1.3em;
font-weight: 600;
}}
.timebox-item {{
background: linear-gradient(135deg, #f8f5fa 0%, #f0ebf5 100%);
padding: 20px;
margin-bottom: 15px;
border-radius: 12px;
border: 2px solid #d4b8e8;
min-height: 120px;
display: flex;
flex-direction: column;
gap: 8px;
transition: all 0.3s;
}}
.timebox-item:hover {{
box-shadow: 0 4px 12px rgba(142, 68, 173, 0.3);
transform: translateX(5px);
}}
.timebox-item.done {{
opacity: 0.6;
background: linear-gradient(135deg, #e8e8e8 0%, #d8d8d8 100%);
}}
.timebox-time {{
font-size: 1.1em;
font-weight: 700;
color: #8e44ad;
}}
.timebox-task-name {{
font-size: 1em;
color: #333;
font-weight: 500;
flex: 1;
}}
.timebox-item.done .timebox-task-name {{
text-decoration: line-through;
}}
.timebox-amount {{
font-size: 1.2em;
font-weight: 700;
color: #6c3483;
}}
.timebox-actions {{
display: flex;
gap: 10px;
align-items: center;
justify-content: flex-end;
}}
.delete-btn-small {{
background: #e74c3c;
color: white;
border: none;
border-radius: 6px;
padding: 5px 10px;
cursor: pointer;
font-size: 1em;
transition: all 0.2s;
}}
.delete-btn-small:hover {{
background: #c0392b;
transform: scale(1.1);
}}
.timebox-empty {{
text-align: center;
padding: 40px 20px;
color: #888;
font-style: italic;
}}
.task-item {{
background: white;
padding: 15px;
margin-bottom: 15px;
border-radius: 12px;
border: 2px solid #e8d8f5;
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.3s;
}}
.task-item:hover {{
box-shadow: 0 4px 12px rgba(142, 68, 173, 0.2);
transform: translateY(-2px);
}}
.task-item.done {{
background: #f5f0f8;
opacity: 0.7;
border-color: #d4b8e8;
}}
.task-left {{
display: flex;
align-items: center;
gap: 15px;
flex: 1;
}}
.task-checkbox {{
width: 24px;
height: 24px;
cursor: pointer;
accent-color: #8e44ad;
}}
.task-info {{
flex: 1;
}}
.task-name {{
font-size: 1.1em;
color: #333;
margin-bottom: 5px;
font-weight: 500;
}}
.task-item.done .task-name {{
text-decoration: line-through;
}}
.task-date {{
font-size: 0.8em;
color: #888;
}}
.task-right {{
display: flex;
align-items: center;
gap: 15px;
}}
.task-amount {{
font-size: 1.3em;
font-weight: 700;
color: #8e44ad;
}}
.delete-btn {{
background: #e74c3c;
color: white;
border: none;
border-radius: 8px;
padding: 8px 12px;
cursor: pointer;
font-size: 1.2em;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
}}
.delete-btn:hover {{
background: #c0392b;
transform: scale(1.1);
}}
.delete-btn:active {{
transform: scale(0.95);
}}
.empty-state {{
text-align: center;
padding: 40px;
color: #888;
}}
.empty-state-icon {{
font-size: 3em;
margin-bottom: 15px;
}}
@media (max-width: 1024px) {{
body {{
flex-direction: column;
}}
.timebox-container {{
width: 100%;
max-height: 400px;
}}
.container {{
max-height: none;
}}
}}
@media (max-width: 600px) {{
.container, .timebox-container {{
border-radius: 0;
}}
h1 {{
font-size: 1.8em;
}}
.form-row {{
flex-direction: column;
}}
.task-item {{
flex-direction: column;
align-items: flex-start;
gap: 10px;
}}
.task-amount {{
align-self: flex-end;
}}
}}
</style>
</head>
<body>
<div class="timebox-container">
<div class="timebox-header">⏰ Time Schedule</div>
<div class="timebox-section" id="timeboxList">
{timebox_html if timebox_html else '<div class="timebox-empty">No timed tasks yet</div>'}
</div>
</div>
<div class="container">
<div class="header">
<h1>Task Manager</h1>
</div>
<div class="total-section">
<div class="total-label">Running Total</div>
<div class="total-amount" id="runningTotal">₹{running_total:.2f}</div>
</div>
<div class="add-task-section">
<form id="taskForm">
<div class="form-row">
<input type="text" id="taskName" placeholder="Task name" required>
<input type="number" id="taskAmount" placeholder="Amount" step="0.01" required>
</div>
<div class="time-inputs">
<span class="time-label">⏰ Schedule:</span>
<div class="time-group">
<select id="timeFromHour">
<option value="">HH</option>
{' '.join([f'<option value="{{i:02d}}">{i:02d}</option>' for i in range(1, 13)])}
</select>
<select id="timeFromMin">
<option value="">MM</option>
{' '.join([f'<option value="{{i:02d}}">{i:02d}</option>' for i in range(0, 60, 15)])}
</select>
<select id="timeFromPeriod">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
</div>
<span class="time-label">to</span>
<div class="time-group">
<select id="timeToHour">
<option value="">HH</option>
{' '.join([f'<option value="{{i:02d}}">{i:02d}</option>' for i in range(1, 13)])}
</select>
<select id="timeToMin">
<option value="">MM</option>
{' '.join([f'<option value="{{i:02d}}">{i:02d}</option>' for i in range(0, 60, 15)])}
</select>
<select id="timeToPeriod">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
</div>
</div>
<button type="submit" class="add-btn">Add Task</button>
</form>
</div>
<div class="tasks-section" id="tasksList">
{tasks_html if tasks_html else '<div class="empty-state"><div class="empty-state-icon">📋</div><div>No tasks yet</div></div>'}
</div>
</div>
<script>
// Add new task
document.getElementById('taskForm').addEventListener('submit', async (e) => {{
e.preventDefault();
const taskName = document.getElementById('taskName').value;
const taskAmount = parseFloat(document.getElementById('taskAmount').value);
// Convert 12-hour time to 24-hour format
const convertTo24Hour = (hour, min, period) => {{
if (!hour || !min) return '';
let h = parseInt(hour);
if (period === 'PM' && h !== 12) h += 12;
if (period === 'AM' && h === 12) h = 0;
return `${{h.toString().padStart(2, '0')}}:${{min}}`;
}};
const timeFromHour = document.getElementById('timeFromHour').value;
const timeFromMin = document.getElementById('timeFromMin').value;
const timeFromPeriod = document.getElementById('timeFromPeriod').value;
const timeFrom = convertTo24Hour(timeFromHour, timeFromMin, timeFromPeriod);
const timeToHour = document.getElementById('timeToHour').value;
const timeToMin = document.getElementById('timeToMin').value;
const timeToPeriod = document.getElementById('timeToPeriod').value;
const timeTo = convertTo24Hour(timeToHour, timeToMin, timeToPeriod);
const body = {{task_name: taskName, amount: taskAmount}};
if (timeFrom) body.time_from = timeFrom;
if (timeTo) body.time_to = timeTo;
const response = await fetch('/api/tasks', {{
method: 'POST',
headers: {{'Content-Type': 'application/json'}},
body: JSON.stringify(body)
}});
if (response.ok) {{
location.reload();
}}
}});
// Toggle task completion
document.querySelectorAll('.task-checkbox').forEach(checkbox => {{
checkbox.addEventListener('change', async (e) => {{
const taskId = e.target.dataset.id;
const response = await fetch(`/api/tasks/${{taskId}}/toggle`, {{
method: 'PUT'
}});
if (response.ok) {{
location.reload();
}}
}});
}});
// Delete task
document.querySelectorAll('.delete-btn, .delete-btn-small').forEach(button => {{
button.addEventListener('click', async (e) => {{
const taskId = e.target.dataset.id;
if (confirm('Are you sure you want to delete this task?')) {{
const response = await fetch(`/api/tasks/${{taskId}}`, {{
method: 'DELETE'
}});
if (response.ok) {{
location.reload();
}}
}}
}});
}});
</script>
</body>
</html>
"""
# Routes
@app.get("/", response_class=HTMLResponse)
def home():
return render_page()
@app.post("/api/tasks")
async def create_task(task_data: TaskCreate):
"""Create a new task and save to TodoTasks.json"""
with file_lock:
todo_tasks = load_json_file(TODO_FILE)
# Get all tasks to determine next ID
all_tasks = todo_tasks + load_json_file(DONE_FILE)
new_id = get_next_id(all_tasks)
new_task = {
"id": new_id,
"task_name": task_data.task_name,
"amount": task_data.amount,
"created_at": datetime.now().isoformat(),
"date": get_today_date()
}
if task_data.time_from:
new_task["time_from"] = task_data.time_from
if task_data.time_to:
new_task["time_to"] = task_data.time_to
todo_tasks.append(new_task)
save_json_file(TODO_FILE, todo_tasks)
return {"id": new_id, "task_name": task_data.task_name, "amount": task_data.amount}
@app.get("/api/tasks")
def get_tasks():
"""Get all tasks for today"""
with file_lock:
todo_tasks = load_json_file(TODO_FILE)
done_tasks = load_json_file(DONE_FILE)
today = get_today_date()
# today_tasks = [t for t in todo_tasks if t['date'] == today]
done_task_ids = {t['id'] for t in done_tasks}
result = []
for task in todo_tasks:
is_done = task['id'] in done_task_ids
completed_at = None
if is_done:
done_task = next((t for t in done_tasks if t['id'] == task['id']), None)
if done_task:
completed_at = done_task['completed_at']
result.append({
"id": task['id'],
"task_name": task['task_name'],
"amount": task['amount'],
"is_done": is_done,
"created_at": task['created_at'],
"completed_at": completed_at
})
return result
@app.put("/api/tasks/{task_id}/toggle")
def toggle_task(task_id: int):
"""Toggle task completion status"""
with file_lock:
todo_tasks = load_json_file(TODO_FILE)
done_tasks = load_json_file(DONE_FILE)
# Find the task in todo list
task = next((t for t in todo_tasks if t['id'] == task_id), None)
if not task:
raise HTTPException(status_code=404, detail="Task not found")
# Check if already done
is_done = any(t['id'] == task_id for t in done_tasks)
if is_done:
# Remove from done list (uncomplete)
done_tasks = [t for t in done_tasks if t['id'] != task_id]
save_json_file(DONE_FILE, done_tasks)
return {"id": task_id, "is_done": False}
else:
# Add to done list
done_task = {
"id": task['id'],
"task_name": task['task_name'],
"amount": task['amount'],
"created_at": task['created_at'],
"completed_at": datetime.now().isoformat(),
"date": task['date'],
"printed": False
}
if task.get('time_from'):
done_task['time_from'] = task['time_from']
if task.get('time_to'):
done_task['time_to'] = task['time_to']
done_tasks.append(done_task)
save_json_file(DONE_FILE, done_tasks)
return {"id": task_id, "is_done": True}
@app.get("/api/total")
def get_total():
"""Get running total"""
total = get_running_total()
return {"running_total": total}
@app.delete("/api/tasks/{task_id}")
def delete_task(task_id: int):
"""Delete a task completely from both JSON files"""
with file_lock:
todo_tasks = load_json_file(TODO_FILE)
done_tasks = load_json_file(DONE_FILE)
# Find and remove from todo list
todo_tasks = [t for t in todo_tasks if t['id'] != task_id]
# Find and remove from done list
done_tasks = [t for t in done_tasks if t['id'] != task_id]
save_json_file(TODO_FILE, todo_tasks)
save_json_file(DONE_FILE, done_tasks)
return {"success": True, "message": "Task deleted"}
@app.get("/next_task")
def get_next_task():
"""Get latest unprinted completed task and mark it as printed"""
with file_lock:
done_tasks = load_json_file(DONE_FILE)
if not done_tasks:
return {}
# Filter unprinted tasks (tasks without 'printed' field or with printed=False)
unprinted_tasks = [t for t in done_tasks if not t.get('printed', False)]
if not unprinted_tasks:
return {}
# Get latest unprinted task by completed_at timestamp
latest_task = max(unprinted_tasks, key=lambda x: x['completed_at'])
# Mark as printed
for task in done_tasks:
if task['id'] == latest_task['id']:
task['printed'] = True
break
save_json_file(DONE_FILE, done_tasks)
return {
"task": latest_task['task_name'],
"amount": str(latest_task['amount']),
"completed_at": latest_task['completed_at']
}