-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path___Jarvis AI___.py
417 lines (379 loc) · 17.7 KB
/
___Jarvis AI___.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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import pyautogui # pip install pyautogui
import smtplib
import requests as r
from PIL import Image
from PyPDF2 import*
import win32api,time,win32con,random
def AI():
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
# it will open chrome browser register your browser and path here
webbrowser.register('chrome',
None,
webbrowser.BackgroundBrowser("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"))
def pdfmerge():
import Browse
import PDFMerg as PM
import Merger as M
PM.replace('PDFMerg.txt','/','\\\\')
print("\nPath of Your File\n", PM.read())
print('''\nExample:= "C:\\Users\\Shivam\\Downloads\\CamScanner 07-28-2020 13.22.15.pdf","D:\\Users\\Shivam\\Downloads\\New Doc 2020-07-21 19.27.15.pdf" ''')
print("\nNote := The file In C Drive will be First And file in D drive will be Second")
print('''\nExample (only for one file):= "C:\\Users\\Shivam\\Downloads\\CamScanner 07-28-2020 13.22.15.pdf",''')
print("\nNote:= Protected Pdf Need To Be Decrepted First By User")
print("\n Any Error Will Exit The Program")
print("\n You Can Change the order of PDF Files to be Merged")
print(' remove "", or " ", from Path Pasted ')
M.merger()
os.system("YourMergedPDF.pdf")
speak("done")
def image(x):
try:
img = Image.open('files\\'+x+'.png')
img.save('files\\'+ x + ' .ico')
except OSError:
print("Image file extension is only valid")
speak("Image file extension is only valid")
image()
finally:
print("done")
speak("done")
def covid():
speak("covid 19 information")
d=r.get("https://api.covid19india.org/data.json")
re=d.json()
x=input("Enter State : ")
t=re['statewise']
for i in t:
if str(i['state']).upper()==x.upper():
print(i['state']+"::")
speak(i['state']+"::")
print("Confirmed Cases : "+ i["confirmed"])
speak("Confirmed Cases : "+ i["confirmed"])
print("Active Cases : "+ i["active"])
speak("Active Cases : "+ i["active"])
print("Deaths : "+ i["deaths"])
speak("Deaths : "+ i["deaths"])
print("Recovered Cases : "+ i["recovered"])
speak("Recovered Cases : "+ i["recovered"])
def speak(audio):
engine.say(audio)
engine.runAndWait()
def typethis(sentence=None,shift=False,control=False,delay=0.05,random_delay=0.05):
for letter in sentence:
time.sleep(random.random()*random_delay) # Makes it look like real typing
c=letter
punctflag = True
if (letter>='A' and letter<='Z') or shift:
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
punctflag = False
if letter>='a' and letter<='z':
c=letter.upper()
punctflag = False
if ((letter>='0' and letter<='9') or (letter==' ')):
punctflag=False
if control:
win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
if not punctflag: # Do this for real letters on the keyboard
if isinstance(letter,(int)):
ordletter=letter
else:
ordletter=ord(c)
win32api.keybd_event(ordletter, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(ordletter, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
if control:
win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)
if (letter>='A' and letter<='Z') or shift:
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
# This must be some punctuation - try to deal with it.
# win32con doesn't include OEM
else:
if letter=='.':
win32api.keybd_event(190, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(190, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter==',':
win32api.keybd_event(188, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(188, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='-':
win32api.keybd_event(189, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(189, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='?':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(191, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(191, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='!':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(ord('1'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(ord('1'), 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='>':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(190, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(190, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='<':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(188, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(188, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='~':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(192, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(192, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='(':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(ord('9'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(ord('9'), 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter==')':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(ord('0'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(ord('0'), 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='+':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(107, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(107, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
elif letter=='/':
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
time.sleep(delay)
win32api.keybd_event(111, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(delay)
win32api.keybd_event(111, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(win32con.VK_SHIFT, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(delay)
win32api.keybd_event(13, 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
# There is a carriage return at the end of each newline
if delay>0.0:
time.sleep(delay)
win32api.keybd_event(13, 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
'''def typefromfile(filename):
with open(filename, 'r') as fopen: # with automatically closes the file
for line in fopen:
typethis(line)
time.sleep(3)''' # switch focus to a target window manually in this time.
# Edit below this point to change what it types.
# Supports lowercase and uppercase letters,
# numbers, and . , - ! ? (depending on your keyboard layout)
#typethis("What is happening?")
#typefromfile("C:/Users/User/Desktop/ghost.txt")
#typethis("all this should be in capslock", shift=True)
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour>=12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("I am Jarvis . Please tell me how could I help you")
def takeCommand():
#It takes microphone input from the user and returns string output
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(f"User said: {query}\n")
except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return query
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('youremail@gmail.com', 'your-password')
server.sendmail('youremail@gmail.com', to, content)
server.close()
if __name__ == "__main__":
wishMe()
while True:
# if 1:
query = takeCommand().lower()
# Logic for executing tasks based on query
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'open youtube' in query:
speak("opening youtube")
webbrowser.get('chrome').open("youtube.com")
elif 'open google' in query:
speak("opening google")
webbrowser.get('chrome').open("google.com")
elif 'play music' in query:
speak("plating music")
music_dir = 'Songs\\'
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))
elif 'time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Hello, the time is {strTime}")
elif 'open' in query:
codePath = ('files\\')
a=str(query)
speak("opening "+a)
os.system('"'+str(codePath+str(a[5:])+".py"+'"'))
elif 'email to ' in query:
try:
speak("What should I say?")
content = takeCommand()
to = '"'+query[9:]+'"'
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry my friend xyzw. I am not able to send this email")
elif 'search' in query :
a=str(query)
b=a[7:]
speak("searching "+b)
webbrowser.get('chrome').open(b)
elif 'refresh' in query :
speak("refreshing.......")
AI()
elif 'are you there' in query :
speak("Yes I am There")
elif 'print' in query :
#a=str(query)
print(query[6:]+"\n")
pyautogui.keyDown(query[6:])
pyautogui.typewrite(query[6:])
elif 'covid' in query :
a=str(query)
print(a[6:])
covid()
elif 'png to icon' in query :
a=str(query)
print(a[12:])
image(a[12:])
elif 'merge' in query:
pdfmerge()
elif 'speak' in query:
speak("please give me the input")
x=input("INPUT A WORD : ")
speak(x)
elif 'type' in query:
print(query[5:]+"\n")
typethis(query[5:])
elif 'start chrome' in query:
speak("starting chrome")
os.startfile("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
elif 'start firefox' in query:
speak("starting firefox")
os.startfile("C:\Program Files\Mozilla Firefox\Firefox.exe")
elif 'start notepad' in query:
speak("starting notepad")
os.system("Notepad")
elif 'start explorer' in query:
speak("starting explorer")
os.startfile("C:\Windows\Explorer.exe")
elif 'start wordpad' in query:
speak("starting wordpad")
os.startfile("C:\Program Files\Windows NT\Accessories\wordpad.exe")
elif 'start paint' in query:
speak("starting paint")
os.startfile("C:\Windows\System32\mspaint.exe")
elif 'start command prompt' in query:
speak("starting command prompt")
os.startfile("C:\Windows\System32\cmd.exe")
elif 'start control pannel' in query:
speak("starting control pannel")
os.startfile("C:\Windows\System32\control.exe")
elif 'start winrar' in query:
speak("starting winrar")
os.startfile("C:\Program Files\WinRAR\WinRAR.exe")
elif 'start winzip' in query:
speak("starting winzip")
os.startfile("C:\Program Files (x86)\WinZip\WINZIP32.EXE")
elif 'start calculator' in query:
speak("starting calaulator")
os.startfile("C:\Windows\system32\calc.exe")
elif 'play video' in query:
speak("plating video")
video_dir = 'Videos\\'
videos = os.listdir(video_dir)
print(videos)
os.startfile(os.path.join(video_dir, videos[0]))
try:
AI()
except:
AI()
else:
AI()
finally:
AI()