-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLI.py
More file actions
190 lines (152 loc) · 4.43 KB
/
CLI.py
File metadata and controls
190 lines (152 loc) · 4.43 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
import requests
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.live import Live
from rich.prompt import Prompt
import time
console = Console()
input = Prompt.ask
API = "http://127.0.0.1:8001"
def animate_welcome():
console.clear()
colors = ["red", "orange1", "yellow", "green", "cyan", "blue", "violet"]
with Live(console=console, refresh_per_second=3) as live:
for _ in range(1):
for color in colors:
live.update(
Panel.fit(
f"[bold {color}]🚀 Welcome to Notes & Task Manager CLI[/]",
title=f"[bold {color}]WELCOME[/]",
border_style=color,
padding=(1, 2),
)
)
time.sleep(0.1)
def add_task():
console.clear()
console.print("\n[bold red]➕ Add New Task[/]")
title = input("Title: ")
description = input("Description: ")
type_ = input("Type (task/note): ").lower()
priority = input("Priority (Low/Medium/High)", choices=["1","2","3"], default="1")
if priority == "1":
priority = "LOW"
pass
elif priority == "2":
priority = "MEDIUM"
pass
elif priority == "3":
priority = "HIGH"
pass
else:
console.print("[bold red]:warning: Something wrong[/]")
tags = input("Tags (comma separated): ").split(",")
due_date = input("Due Date (YYYY-MM-DD or blank): ") or None
payload = {
"title": title,
"description": description,
"type": type_,
"priority": priority,
"tags": tags,
"due_date": due_date,
}
r = requests.post(f"{API}/add", json=payload)
if r.status_code == 200:
console.print(r.json())
else:
console.print("[bold red]:warning: Something wrong[/]")
def list_tasks():
console.clear()
console.print("\n[bold orange]📋 All Tasks[/]")
r = requests.get(f"{API}/all")
data = r.json()
if data["status"] != 200:
console.print("❌ No data found")
return
table = Table(title="Tasks")
table.add_column("ID", style="red")
table.add_column("Title")
table.add_column("Type")
table.add_column("Priority")
table.add_column("Status")
table.add_column("Due Date")
for item in data["data"]:
table.add_row(
item["_id"],
item["title"],
item["type"],
item["priority"],
item["status"],
str(item.get("due_date", "-")),
)
console.print(table)
def update_task():
console.clear()
console.print("\n[bold yellow]✏️ Update Task[/bold yellow]")
item_id = input("Enter Task ID: ")
status = input("New Status (Pending/Done or blank): ") or None
priority = input("Priority (Low/Medium/High)", choices=["1","2","3"], default="")
if priority == "1":
priority = "LOW"
pass
elif priority == "2":
priority = "MEDIUM"
pass
elif priority == "3":
priority = "HIGH"
pass
else:
priority = None
payload = {
"status": status,
"priority": priority,
}
r = requests.put(f"{API}/update/{item_id}", json=payload)
console.print(r.json())
def delete_task():
console.clear()
console.print("\n[bold red]🗑 Delete Task[/bold red]")
item_id = input("Enter Task ID: ")
r = requests.delete(f"{API}/delete/{item_id}")
console.print(r.json())
def delete_all():
console.clear()
confirm = input("Are you sure? (yes/no): ")
if confirm.lower() == "yes":
r = requests.delete(f"{API}/delete-all")
console.print(r.json())
def menu():
while True:
console.print(
"""
[bold green]
1. Add Task
2. View All Tasks
3. Update Task
4. Delete Task
5. Delete All
0. Exit
[/]
"""
)
choice = input("Choose option", choices=["1","2","3","4","5","0"])
if choice == "1":
add_task()
elif choice == "2":
list_tasks()
elif choice == "3":
update_task()
elif choice == "4":
delete_task()
elif choice == "5":
delete_all()
elif choice == "0":
console.clear()
console.print("👋 Bye!")
break
else:
console.print("❌ Invalid choice")
if __name__ == "__main__":
animate_welcome()
menu()