-
Notifications
You must be signed in to change notification settings - Fork 2
/
digital_assistant.py
401 lines (350 loc) · 13.4 KB
/
digital_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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#MIT License
#Copyright (c) 2020 Viswanadh Kothakota
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
import datetime
import os, random
import webbrowser
import wikipedia
import time
import speedtest
import requests, json
import pyautogui
import control_keys
from time import ctime
from RespondListen import respond, listen
from googlesearch import search
from ecapture import ecapture as ec
from camera import face_rec, New_access
from Calendar import calendar_events, create_event
from tictactoe import tic_tac_toe
from control_keys import Tab_Opt, Win_Opt, Ctrl_Keys
from system_specs import System_specs
keys=control_keys.General_keys()
webbrowser.register('chrome',
None,
webbrowser.BackgroundBrowser("C://Program Files (x86)//Google//Chrome//Application//chrome.exe"))
def init_check():
if internet_availability():
pre_init()
if face_rec():
return True
else:
return False
else:
return False
def pre_init():
respond("hi sir! You are activated Jarvis, But In orded to activate all the functions of Jarvis I have to recognize you sir ")
respond("So, A facial recognition is under process, please wait!")
def intiate_jarvis():
respond("checking remote servers!")
respond("importing preferences and loading all the system drivers!")
respond("establish secure connection!")
os.startfile("c:\\Program files\\Rainmeter\\Rainmeter.exe")
respond("secure connection established!")
respond("we are online!")
respond("welcome back sir!")
wishme()
respond("Jarvis is at your service")
def wishme():
hour=datetime.datetime.now().hour
if hour>=0 and hour<12:
respond("Good Morning")
elif hour>=12 and hour<18:
respond("Good Afternoon")
else:
respond("Good Evening")
def contain(data,words):
for word in words:
if word in data:
return True
return False
def internet_availability():
try:
url = "http://google.com/"
timeout = 2
_ = requests.get(url, timeout = timeout)
return True
except:
respond("No internet connection!")
return False
def access():
respond("Are you confirm in access control transfer!")
data = listen()
if "confirm" in data or "yes" in data or "yeah" in data:
respond("could you please say the name of the person of whom you are going to give access")
name = listen()
respond("okay")
respond("new visual confirmation required!")
New_access(name)
respond("access control transferred successfully!")
return
else:
respond("are you sure in cancelling access control transfer!")
data = listen()
if data == "yes":
return
else:
access()
def execute_commands():
try:
respond("okay sir!")
respond("please give me the list of instruction to execute")
a=[]
while True:
data = listen()
if "that's it" in data:
break
else:
a.append(data)
respond("okay")
for instruct in a:
speech="your instruction {} is going to execute sir!".format(instruct)
respond(speech)
digital_assistant(instruct)
except:
respond("sorry sir, there is an error occurred. Could you plese repeat commands to do!")
return
def digital_assistant(data):
try:
if data == "jarvis":
respond("yes sir! I am at your service")
return
elif "how are you" in data:
respond("I am well")
return
elif contain(data,["define yourself","what can you do","who are you"]):
respond("I am viswanadh's personal assistant, I am programmed to do minor tasks like system monitoring, profiling,"
"predict time, take a photo, predict weather,"
" opening applications like youtube, google chrome ,gmail etcetre, show the top headline news and you can ask me computational or geographical questions too!")
return
elif contain(data,["who made you","who created you"]):
respond("I was built by viswa")
return
elif "shutdown" in data:
respond("Are you sure! you want to shutdown your computer")
data = listen()
if data == "yes":
respond("system is going to shutdown...")
os.system("taskkill /f /im Rainmeter.exe")
os.system("shutdown /s /t 1")
return
elif "restart" in data:
respond("want to restart your computer")
data=listen()
if data=="yes":
os.system("shutdown /r /t 1")
return
elif "music" in data:
respond("Here you go with music")
music_dir = "C:\\Users\\VISWANADH\\Music"
song = random.choice(os.listdir(music_dir))
os.startfile(os.path.join(music_dir,song))
time.sleep(5)
return
elif "movie" in data:
os.system("D:\\movies\\Ala_Vaikunthapurramloo.mkv")
time.sleep(5)
return
elif "notepad" in data:
os.system("notepad")
return
elif contain(data,['select all','cut','copy','paste','history','download','undo','redo','save','enter','search','find']):
Ctrl_Keys(data)
return
elif "open" in data:
if "tab" in data:
Tab_Opt(data)
time.sleep(10)
respond("what do you wanna search sir!")
data = listen()
if "search" in data:
keys.Paste()
else:
pyautogui.typewrite(data)
keys.Enter()
elif "window" in data:
Win_Opt(data)
elif "chrome" in data:
time.sleep(3)
webbrowser.open("http://www.google.com/")
time.sleep(10)
respond("what do you wanna search sir!")
data = listen()
if "search" in data:
keys.Paste()
else:
pyautogui.typewrite(data)
keys.Enter()
else:
data = data.split(" ")
query = data[1]
for j in search(query, tld='com', lang='en', num=1, start=0, stop=1, pause=2.0):
url=j
webbrowser.get('chrome').open_new(url)
respond(data[1] + " is open now")
time.sleep(7)
return
elif "news" in data:
query = "news"
url="https://timesofindia.indiatimes.com/home/headlines"
webbrowser.get('chrome').open_new(url)
respond("Here are some headlines from the Times of India,Happy reading")
time.sleep(5)
return
elif "weather" in data:
data=data.split(" ")
api_key = "###############################"
base_url = "https://api.openweathermap.org/data/2.5/weather?"
if "in" not in data:
city_name = "kurupam"
else:
city_name = data[-1]
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
response = requests.get(complete_url)
x = response.json()
if x["cod"] != "404":
y = x["main"]
current_temperature = y["temp"]
current_humidiy = y["humidity"]
z = x["weather"]
weather_description = z[0]["description"]
respond(" Temperature in kelvin unit at " + city_name + " is " +
str(current_temperature) +
"\n humidity in percentage is " +
str(current_humidiy) +
"\n description " +
str(weather_description))
return
else:
respond(city_name + " weather details not found")
return
elif "something" in data:
respond("Searching...")
data=data.split(" ")
data = data[3:]
Req_data = ""
for word in data:
Req_data = Req_data + " " + word
data = "According to wikipedia " + wikipedia.summary(Req_data, sentences=4)
respond(data)
return
elif contain(data,["take a photo","capture the photo"]):
ec.capture(0,False,"img.jpg")
respond("photo captured successfully")
return
elif contain(data,["video","record the video"]):
ec.auto_vidcapture(0,False,"video.mkv",10)
respond("video recorded successfully")
return
elif "access" in data:
access()
return
elif "where is" in data:
data = data.split(" ")
name = data[-1]
url = "https://www.google.com/maps/place/"+name
webbrowser.get('chrome').open_new(url)
time.sleep(5)
return
elif "write a note" in data:
respond("What should i write, sir!")
data = listen()
file = open('note.txt', 'a')
file.write("\n"+ctime()+"\n")
file.write(data)
respond("noted successfully")
return
elif "execute" in data:
execute_commands()
return
elif contain(data,["upcoming events","scheduled events","events"]):
calendar_events()
return
elif contain(data,["game","play"]):
try:
tic_tac_toe()
return
except:
return
elif "create event" in data:
create_event()
return
elif contain(data,["speed test","internet speed"]):
try:
respond("sure! wait a second to measure")
st = speedtest.Speedtest()
server_names = []
st.get_servers(server_names)
ping = st.results.ping
downlink_Mbps = round(st.download() / 1000000, 2)
uplink_Mbps = round(st.upload() / 1000000, 2)
respond('ping {} ms'.format(ping))
respond("The uplink is {} Mbps".format(uplink_Mbps))
respond("The downlink is {}Mbps".format(downlink_Mbps))
return
except:
respond ("I couldn't run a speedtest")
return
elif contain(data,["internet connection","connection"]):
if internet_availability():
respond("Internet Connection is okay!")
return
elif "wait" in data:
respond("okay sir")
time.sleep(10)
return
elif "screenshot" in data:
Screenshot = pyautogui.screenshot()
dir = "C:\\Users\VISWANADH\Pictures\Screenshots"
length = len(os.listdir(dir))
Screenshot_name = "Screenshot({}).png".format(length)
path = os.path.join(dir,Screenshot_name)
Screenshot.save(path)
respond("Screenshot saved Successfully!")
return
elif "tab" in data:
Tab_Opt(data)
return
elif "window" in data:
Win_Opt(data)
return
elif contain(data,['battery', 'cpu', 'memory', 'brightness']):
System_specs(data)
return
elif "time" in data:
respond(ctime())
return
else:
respond("I can search the web for you,Do you want to continue?")
opinion=listen()
if opinion=="yes":
url="https://www.google.com/search?q =" + '+'.join(data.split())
webbrowser.get('chrome').open_new(url)
time.sleep(5)
return
else:
return
except:
respond("I don't understand, I can search the web for you,Do you want to continue?")
opinion=listen()
if opinion=="yes":
url="https://www.google.com/search?q =" + '+'.join(data.split())
webbrowser.get('chrome').open_new(url)
time.sleep(5)
return
else:
return