forked from suryanshsk/Python-Voice-Assistant-Suryanshsk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_automation.py
145 lines (117 loc) · 4.91 KB
/
task_automation.py
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
import smtplib
import time
import json
import sqlite3
import schedule
from datetime import datetime, timedelta
def send_email(subject, body, to_email):
try:
smtp_server = 'smtp.gmail.com'
smtp_port = 587
sender_email = 'youremailid'
send_password = 'yourpassword'
message = f'Subject: {subject}\n\n{body}'
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(sender_email, send_password)
server.sendmail(sender_email, to_email, message)
print(f"Email sent to {to_email}'")
except Exception as e:
print(f"Something went wrong: {e}")
class TodoList:
def __init__(self, db_name='todo_list.db'):
self.connection = sqlite3.connect(db_name)
self.create_table()
def create_table(self):
with self.connection:
self.connection.execute('''
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY,
task TEXT NOT NULL,
completed BOOLEAN NOT NULL,
priority TEXT,
due_date TEXT
)
''')
def clear_tasks(self):
with self.connection:
self.connection.execute('DELETE FROM tasks')
print("All tasks cleared.")
def add_task(self, task, priority='medium', due_date=None):
with self.connection:
self.connection.execute('''
INSERT INTO tasks (task, completed, priority, due_date)
VALUES (?, ?, ?, ?)
''', (task, False, priority, due_date))
print(f"Task added successfully: {task}")
def complete_task(self, task_id):
with self.connection:
self.connection.execute('''
UPDATE tasks SET completed = ? WHERE id = ?
''', (True, task_id))
print(f"Task completed no. : {task_id}")
def delete_task(self, task_id):
with self.connection:
self.connection.execute('''
DELETE FROM tasks WHERE id = ?
''', (task_id,))
print(f"Task deleted no. : {task_id}")
def edit_task(self, task_id, new_task=None, new_priority=None, new_due_date=None):
with self.connection:
if new_task:
self.connection.execute('''
UPDATE tasks SET task = ? WHERE id = ?
''', (new_task, task_id))
if new_priority:
self.connection.execute('''
UPDATE tasks SET priority = ? WHERE id = ?
''', (new_priority, task_id))
if new_due_date:
self.connection.execute('''
UPDATE tasks SET due_date = ? WHERE id = ?
''', (new_due_date, task_id))
print(f"Task edited: {task_id}")
def show_tasks(self):
cursor = self.connection.cursor()
cursor.execute('SELECT * FROM tasks')
tasks = cursor.fetchall()
if not tasks:
print("None of the tasks are available")
else:
for task in tasks:
status = '✓' if task[2] else '✗'
print(f"{task[0]}: [{status}] {task[1]} (priority: {task[3]}) Due: {task[4]}")
def search_tasks(self, keyword):
cursor = self.connection.cursor()
cursor.execute('SELECT * FROM tasks WHERE task LIKE ?', ('%' + keyword + '%',))
tasks = cursor.fetchall()
if not tasks:
print("No matching tasks found")
else:
for task in tasks:
status = '✓' if task[2] else '✗'
print(f"{task[0]}: [{status}] {task[1]} (priority: {task[3]}) Due: {task[4]}")
def schedule_appointment(date_time, task):
def job():
print(f"Appointment reminder: {task}")
schedule.every().day.at(date_time.strftime("%H:%M")).do(job)
print(f"Appointment scheduled for {date_time.strftime('%Y-%m-%d %H:%M')}: {task}")
if __name__ == "__main__":
todo_list = TodoList()
# Clear existing tasks
todo_list.clear_tasks()
# Add new tasks
todo_list.add_task('Complete the assignment', 'high', '2024-10-10')
todo_list.add_task('Buy skin care', 'low')
todo_list.add_task('Physics Numericals', 'high', '2024-10-10')
todo_list.add_task('Send the ppt to HR', 'high', '2024-10-12')
todo_list.show_tasks()
todo_list.complete_task(2)
todo_list.complete_task(4)
todo_list.show_tasks()
todo_list.edit_task(1, new_task='submit the maths assignment too', new_priority='high')
todo_list.show_tasks()
todo_list.delete_task(2)
todo_list.search_tasks('assignment')
appointment_time = datetime.strptime('2024-10-10 05:23', '%Y-%m-%d %H:%M')
schedule_appointment(appointment_time, 'Dentist appointment')