forked from jv40/task-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete_task.py
More file actions
37 lines (35 loc) · 889 Bytes
/
Copy pathcomplete_task.py
File metadata and controls
37 lines (35 loc) · 889 Bytes
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
import json
from datetime import datetime
DATA_FILE="data.json"
def complete_task():
task_id=input("Enter task ID to complete: ").strip()
if not task_id.isdigit():
print("Invalid ID format.")
return
task_id=int(task_id)
with open(DATA_FILE,"r") as f:
data=json.load(f)
found=None
for t in data["tasks"]:
if t["id"] == task_id:
found=t
break
if not found:
print("Task not found.")
return
if found["completed"]:
undo=input("Task is already completed. Undo completion? (yes/no): ")
if undo=="yes":
found["completed"]=False
found["completion_date"]=None
print("Completion undone.")
else:
print("No changes made.")
else:
found["completed"]=True
found["completion_date"]=datetime.now().strftime("%Y-%m-%d")
print("Task marked completed!")
with open(DATA_FILE,"w") as f:
json.dump(data,f,indent=4)
if __name__=="__main__":
complete_task()