forked from Riddhima23/The-Email-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourcecode.py
156 lines (139 loc) · 5.18 KB
/
sourcecode.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
146
147
148
149
150
151
152
153
154
155
#importing modules
import os
import json
import pyttsx3
import speech_recognition as sr
import smtplib
from email.message import EmailMessage
import threading
import queue
from PIL import ImageTk, Image
import tkinter as tk
from tkinter import WORD
from tkinter import messagebox
#sending
def send():
queue.put(e.get())
e.delete(0,tk.END)
#speaking
def speak(text):
bot.say(text)
bot.runAndWait()
# taking input speech command
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
queue.put("Kurama:- Listening...\n")
r.pause_threshold = 1
audio = r.listen(source)
try:
queue.put("Kurama:- Recognizing...\n")
query = r.recognize_google(audio, language='en-in')
print(f"You-->{query}\n")
except Exception as e:
queue.put("Kurama:- Sorry couldn\'t recognise that !\n")
speak("Sorry couldn\'t recognise that !")
query="\quit"
return query
#sending email
def send_email(sender,pwd,receiver, subject, body):
server= smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender,pwd)
email=EmailMessage()
email['From']=sender
email['To']=receiver
email['Subject']=subject
email.set_content(body)
server.send_message(email)
server.close()
#data.json(dictionary to json and vice a versa)
elist = {}
with open('data.json') as file:
elist = json.load(file)
#main loop
def my_loop(queue):
queue.put("Hey pal! This is Kurama , your personal mail assistant, in short the email bot! I will help you in sending emails with minimum effort !\n \n")
speak("Hey pal! This is Kurama , your personal mail assistant, in short the email bot! I will help you in sending emails with minimum effort ! ")
while True:
queue.put("Kurama:- Please enter your email and password:\n")
speak("Please enter your email: and password:")
email=queue.get()
queue.put("Sender: ", email)
password=queue.get()
queue.put("\nKurama:- To whom do you want to send the mail?\n")
speak("To whom do you want to send the mail?")
reply=queue.get()
queue.put("Kurama:- Is the email address of the person you want to send email ,present in our mail list ?\n")
speak("Is the email of the person you want to send email to present in our mail list ?")
queue.put("Email List\n\n")
queue.put(elist)
queue.put("\n\n")
ans=takecommand().lower()
if ans=="\quit":
queue.put("\quit")
break
elif ans=="no":
queue.put("Kurama:- Enter the email of the recipient:\n")
speak("Enter the email of the recipient:")
name=queue.get()
elist[reply] =name
t = len(elist)
with open('data.json', 'a') as outfile:
json.dump(elist, outfile, indent=4)
queue.put("Kurama:- What will be the subject of the mail ?\n")
speak("What will be the subject of the mail?")
sub=takecommand().lower()
if sub=="\quit":
queue.put("\quit")
break
queue.put("You:- "+sub+"\n")
queue.put("Kurama:- What will be the content of your mail ?\n")
speak("What will be the content of your mail?")
content=takecommand().lower()
if content=="\quit":
queue.put("\quit")
break
queue.put("You:- "+content+"\n")
send_email(email,password,elist[reply],sub,content)
speak("Congratulations ! You were able to send your first mail ! Do you want to send more emails or you want to stop ? ")
queue.put("Kurama:- Congratulations! You were able to send your first mail! Do you want to send more emails or you want to stop?\n")
ans=takecommand().lower()
if ans=="\quit":
queue.put("\quit")
break
elif ans=="stop":
queue.put("Kurama-: Sayonara from Kurama ! I hope to see you again ! Till then have a good day! \n")
speak("Sayonara from Kurama ! I hope to see you again ! Till then have a good day ! ")
queue.put("\quit")
break
def update_text():
if not queue.empty():
text = queue.get()
if text == '\quit':
root.destroy()
return
else:
t.insert('end', text)
root.after(200, update_text)
#driving function
if __name__ == "__main__":
bot = pyttsx3.init('sapi5')
bot.setProperty("rate", 155)
voices = bot.getProperty('voices')
bot.setProperty('voice', voices[0].id)
root = tk.Tk()
t = tk.Text(root, height=20, width=100,wrap=WORD)
font_tuple=("Teletype", 10)
e = tk.Entry(root, width=80,fg="white",font=font_tuple,bg="#293552")
e.grid(row=1, column=0)
t.config(background="#07122b",font=font_tuple,fg="white")
send = tk.Button(root, text="Send", command=send,bg="blue violet",font=font_tuple,fg="floral white",activebackground="darkgreen",activeforeground="lightcyan").grid(row=1, column=1)
t.grid(row=0, column=0, columnspan=2)
root.title("KURAMA")
queue = queue.Queue()
update_text()
task = threading.Thread(target=my_loop, args=(queue,))
task.start()
root.mainloop()
task.join()