-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask Manangement system
91 lines (75 loc) · 2.69 KB
/
Task Manangement system
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
import sqlite3
from datetime import datetime
# Connect to SQLite database
conn = sqlite3.connect('tasks.db')
cursor = conn.cursor()
# Create tasks table
cursor.execute('''
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
description TEXT,
due_date TEXT,
priority INTEGER,
status TEXT
)
''')
# Function to add a new task
def add_task(title, description, due_date, priority):
cursor.execute('''
INSERT INTO tasks (title, description, due_date, priority, status)
VALUES (?, ?, ?, ?, ?)
''', (title, description, due_date, priority, 'Pending'))
conn.commit()
# Function to view all tasks
def view_tasks():
cursor.execute('SELECT * FROM tasks')
tasks = cursor.fetchall()
for task in tasks:
print(f'ID: {task[0]}, Title: {task[1]}, Description: {task[2]}, Due Date: {task[3]}, Priority: {task[4]}, Status: {task[5]}')
# Function to update a task status
def update_task_status(task_id, status):
cursor.execute('UPDATE tasks SET status = ? WHERE id = ?', (status, task_id))
conn.commit()
# Function to delete a task
def delete_task(task_id):
cursor.execute('DELETE FROM tasks WHERE id = ?', (task_id,))
conn.commit()
# Main menu
def main():
while True:
print("\nTask Management System")
print("1. Add Task")
print("2. View Tasks")
print("3. Update Task Status")
print("4. Delete Task")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == '1':
title = input("Enter task title: ")
description = input("Enter task description: ")
due_date = input("Enter due date (YYYY-MM-DD): ")
priority = int(input("Enter priority (1-5): "))
add_task(title, description, due_date, priority)
print("Task added successfully!")
elif choice == '2':
view_tasks()
elif choice == '3':
task_id = int(input("Enter task ID to update: "))
status = input("Enter new status (Pending/Completed): ")
update_task_status(task_id, status)
print("Task status updated!")
elif choice == '4':
task_id = int(input("Enter task ID to delete: "))
delete_task(task_id)
print("Task deleted!")
elif choice == '5':
print("Exiting...")
break
else:
print("Invalid choice, please try again.")
# Run the main menu
if __name__ == "__main__":
main()
# Close the database connection when done
conn.close()