-
Notifications
You must be signed in to change notification settings - Fork 0
/
assistant.py
250 lines (225 loc) · 7.84 KB
/
assistant.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import pyttsx3
import datetime
#from datetime import date
import speech_recognition as sr
import wikipedia
import smtplib
import webbrowser as wb
import os
import subprocess
import pyautogui
import psutil
import pyjokes
#import calendar
#from PyDictionary import PyDictionary
engine = pyttsx3.init()
def my_birthday():
speak("How could I forget your birthday? It's on March 10.")
today = datetime.date.today()
bdate = datetime.date(#inputdate)
diff = bdate - today
daydiff=str(diff.days)
speak("There are " + daydiff + "days to it")
def speak(audio):
engine.say(audio)
engine.runAndWait()
def time():
time=datetime.datetime.now().strftime("%H:%M:%S")
speak("The current time is")
speak(time)
def date():
year=datetime.datetime.now().year
day=datetime.datetime.now().strftime("%d")
month = datetime.datetime.now().strftime("%B")
weekday=datetime.datetime.today().strftime("%A")
speak("Today is" + weekday + month + day)
#speak(year)
def greeting():
hour = datetime.datetime.now().hour
#speak(hour)
if hour >= 5 and hour < 12:
speak("Good morning")
elif hour >= 12 and hour < 17:
speak("Good afternoon")
elif hour >= 17 and hour < 20:
speak("Good evening")
else:
speak("")
speak("Hi, I'm Bob")
speak("How can I help you today?")
def sendEmail(to, content):
server=smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('email id', '#password')
server.sendmail('email id', to, content)
server.close()
def cpu():
usage=str(psutil.cpu_percent())
#speak("CPU is at" + usage)
battery=psutil.sensors_battery()
speak("Your battery percentage is")
speak(battery.percent)
if(battery.percent<=20):
speak("Charge your laptop soon")
def jokes():
speak("I like jokes. Let me tell you one")
speak(pyjokes.get_joke())
def screenshot():
img=pyautogui.screenshot()
img.save()
def takeCommand():
r=sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold=1
audio = r.listen(source)
try:
print("Recognizing...")
query=r.recognize_google(audio, language='en-in')
print(query)
except Exception as e:
print(e)
speak("Could you please repeat?")
return "None"
return query
if __name__=="__main__":
greeting()
while True:
query=takeCommand().lower()
if 'time' in query:
time()
elif 'date' in query:
date()
elif 'my birthday' in query:
my_birthday()
elif 'search' in query:
speak("Searching for it right now")
query=query.replace("wikipedia", "")
result=wikipedia.summary(query, sentences=2)
print(result)
speak(result)
elif 'google' in query:
speak("Opening up Google")
wb.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open("http://google.com")
elif 'logout' in query:
speak("Logging out")
os.system('shutdown -l')
elif 'shutdown' in query:
speak("Shutting down")
os.system('shutdown /s /t 1')
elif 'restart' in query:
speak("Restarting")
os.system('shutdown /r /t 1')
elif 'battery' in query:
cpu()
elif "don't understand" in query:
speak("Are my jokes that bad?")
elif 'thank you' in query:
speak("Always here to help")
elif 'thanks' in query:
speak("Welcome");
elif '1 second' in query:
speak("Sure, take your time")
elif 'play the birthday song' in query:
speak("Playing it right away")
wb.open("https://www.youtube.com/watch?v=_z-1fTlSDF0")
elif 'joke' in query:
jokes()
elif 'funny' in query:
jokes()
elif 'spotify' in query:
speak("Opening up Spotify")
subprocess.call(r'C:\Users\rutuj\AppData\Roaming\Spotify\Spotify.exe')
elif 'eclipse' in query:
speak("Opening up Eclipse")
subprocess.call(r'C:\Users\rutuj\eclipse\jee-2020-032\eclipse\eclipse.exe')
elif 'word' in query:
speak("Opening up Word")
subprocess.call(r'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE')
elif 'gmail' in query:
speak("Opening up Google")
wb.open("") #link
elif 'remember' in query:
speak("I'm taking note.")
data=takeCommand()
speak("Adding" + data + "to reminders")
remember=open('bobreminder.txt', 'w')
remember.write(data)
remember.close()
elif 'siri' in query:
speak("I'm going to act like I didn't hear that")
elif 'reminders' in query:
remember=open('bobreminder.txt', 'r')
speak("Your reminders are:" + remember.read())
elif 'restless' in query:
speak("I think you deserve a break. You should listen to some music.")
speak("Opening up Spotify")
subprocess.call(r'C:\Users\rutuj\AppData\Roaming\Spotify\Spotify.exe')
elif 'purpose' in query:
speak("That's a secret")
elif 'youtube' in query:
speak("Opening up Youtube")
wb.open('https://www.youtube.com/')
elif 'bob' in query:
speak("Hi, how are you?")
elif 'how are you' in query:
speak("I'm good, thank you")
elif 'and you' in query:
speak("I'm good, thank you")
elif 'annoyed' in query:
speak("Is <<name>> annoying you?")
elif 'whatsapp' in query:
speak("Opening up whatsapp")
wb.open("https://www.whatsapp.com/")
elif 'dashboard' in query:
speak("Opening up the dashboard you made")
wb.open('') #link
elif 'email yash' in query:
try:
speak("What message do you have?")
content = takeCommand()
to = "#email_id"
speak("The email says:")
speak(content)
speak("Do I send the email?")
queryemail = takeCommand().lower()
if 'yes' in queryemail:
sendEmail(to, content)
speak("The email has been sent")
else:
speak("Alright. Email has been deleted")
#speak("The email has been sent")
except Exception as e:
print(e)
speak("The email could not be sent")
elif 'screenshot' in query:
screenshot()
speak("The screesnhot has been saved")
elif 'wrong' in query:
speak("Did I make a mistake? Wait, I'll try again. Could you please repeat?")
elif 'sleep' in query:
speak("Is it nap time already? ")
elif 'send me an email' in query:
try:
speak("What message do you have?")
content=takeCommand()
to="" #emailid
speak("The email says:")
speak(content)
speak("Do I send the email?")
queryemail= takeCommand().lower()
if 'yes' in queryemail:
sendEmail(to, content)
speak("The email has been sent")
else:
speak("Alright. Email has been deleted")
except Exception as e:
print(e)
speak("The email could not be sent")
elif 'play our song' in query:
speak("I think it's become my favourite. Playing it right now")
wb.open(''); #put link
elif 'bye' in query:
speak("Bye! See you soon")
quit()