Skip to content

Commit 5a8e092

Browse files
committed
CLI Based TODO Application
1 parent 62e23ce commit 5a8e092

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed

CLI-Based-TODO/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# CLI based TODO application
3+
4+
Insted of starting a new application for TODO this new CLI application will help developers easily manage their routine
5+
6+
7+
8+
## Executing the application
9+
10+
Fork this repository and navigate to the CLI-TODO
11+
12+
```bash
13+
.\task
14+
```
15+
16+
## Example
17+
18+
![list](https://user-images.githubusercontent.com/78130964/185183315-4eeb078b-7278-40a5-8127-feee0c00d38e.png)
19+
20+
![ope](https://user-images.githubusercontent.com/78130964/185183470-2162acac-42ad-418a-80a7-d98ee5838a0b.png)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2 hello
2+
2 buy tshirt

CLI-Based-TODO/path/to/plans/task.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 buy rice

CLI-Based-TODO/task.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
python task.py %1 %2 %3

CLI-Based-TODO/task.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import time,os,sys
2+
3+
usage = "Usage :-\n$ ./task add 2 'hello world' # Add a new item with priority 2 and text \"hello world\" to the list\n$ ./task ls # Show incomplete priority list items sorted by priority in ascending order\n$ ./task del INDEX # Delete the incomplete item with the given index\n$ ./task done INDEX # Mark the incomplete item with the given index as complete\n$ ./task help # Show usage\n$ ./task report # Statistics ( list complete/incomplete task )"
4+
5+
def func():
6+
try:
7+
8+
# printing help
9+
if sys.argv[1]=="help":
10+
print(usage)
11+
return usage
12+
13+
# lisiting all the task
14+
if sys.argv[1]=="ls":
15+
try:
16+
f = open("path/to/plans/task.txt",'r')
17+
data = f.read()
18+
datalist = data.split("\n")
19+
datalist = sorted(datalist)
20+
datalist = datalist[1:]
21+
# print(datalist)
22+
for i in range(len(datalist)):
23+
print(f"{i+1}. {datalist[i][2:]} [{datalist[i][0:1]}]")
24+
25+
except:
26+
print("Error: Missing file")
27+
28+
29+
30+
# adding the task
31+
if sys.argv[1]=="add":
32+
try:
33+
with open("path/to/plans/task.txt",'a',encoding = 'utf-8') as f:
34+
res = f.write(f"{sys.argv[2]} {sys.argv[3]}\n")
35+
except:
36+
print("Error: Missing tasks string. Nothing added!")
37+
else:
38+
print(f"Added task: \"{sys.argv[3]}\" with priority {sys.argv[2]}")
39+
40+
41+
42+
# deleting the task
43+
if sys.argv[1]=="del":
44+
lineno = int(sys.argv[2])
45+
try:
46+
with open("path/to/plans/task.txt","r+") as f:
47+
new_f = f.readlines()
48+
new_f = sorted(new_f)
49+
# print(new_f)
50+
del_f = new_f.pop(lineno-1)
51+
# print(new_f)
52+
53+
f.seek(0)
54+
for line in new_f:
55+
if del_f not in line:
56+
f.write(line)
57+
f.truncate()
58+
except:
59+
print(f"Error: item with index {lineno} does not exist. Nothing deleted.")
60+
61+
62+
63+
# marking done
64+
if sys.argv[1]=="done":
65+
lineno = int(sys.argv[2])
66+
try:
67+
with open("path/to/plans/task.txt","r+") as f:
68+
new_f = f.readlines()
69+
new_f = sorted(new_f)
70+
# print(new_f)
71+
del_f = new_f.pop(lineno-1)
72+
# print(new_f)
73+
74+
f.seek(0)
75+
for line in new_f:
76+
if del_f not in line:
77+
f.write(line)
78+
with open("path/to/plans/completed.txt","a") as r:
79+
r.write(del_f)
80+
f.truncate()
81+
82+
83+
84+
except:
85+
print(f"Error: no incomplete item with index #0 exists.")
86+
else:
87+
print(f"Marked item as done.")
88+
89+
90+
# generating the report
91+
if sys.argv[1]=="report":
92+
try:
93+
task = open("path/to/plans/task.txt",'r')
94+
data = task.read()
95+
datalist = data.split("\n")
96+
datalist = sorted(datalist)
97+
datalist = datalist[1:]
98+
print(f"Pending : {len(datalist)}")
99+
for i in range(len(datalist)):
100+
print(f"{i+1}. {datalist[i][2:]} [{datalist[i][0:1]}]")
101+
102+
compt = open("path/to/plans/completed.txt",'r')
103+
data = compt.read()
104+
datalist = data.split("\n")
105+
datalist = sorted(datalist)
106+
datalist = datalist[1:]
107+
print(f"Completed : {len(datalist)}")
108+
for i in range(len(datalist)):
109+
print(f"{i+1}. {datalist[i][2:]} [{datalist[i][0:1]}]")
110+
except:
111+
print("Error: Missing file")
112+
113+
except:
114+
print(usage)
115+
return usage.encode('utf8')
116+
117+
func()

0 commit comments

Comments
 (0)