forked from zapellass123/OpenEmailGenerator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jarvis.py
278 lines (230 loc) · 8.67 KB
/
Jarvis.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
import pyttsx3 # pip install pyttsx3
import datetime
import speech_recognition as sr # pip install speech_recognition
import wikipedia # pip install wikipedia
import smtplib
import webbrowser as wb
import psutil # pip install psutil
import pyjokes # pip install pyjokes
import os
import pyautogui # pip install pyautogui
import wolframalpha # pip install wolframalpha
import tkinter as tk
from tkinter import filedialog
import json
from urllib.request import urlopen
import time
engine = pyttsx3.init()
wolframalpha_app_id = '725EY8-2JJ8XA7E4H'
def speak(audio):
engine.say(audio)
engine.runAndWait()
def time_():
Time = datetime.datetime.now().strftime("%I:%M:%S") # H is for 24 hrs clock and I for 12 hrs clock
speak("The current time is")
speak(Time)
def joke():
speak(pyjokes.get_joke())
def screenshot():
img = pyautogui.screenshot()
img.save("screenshot.png")
def date_():
year = datetime.datetime.now().year
month = datetime.datetime.now().month
day = datetime.datetime.now().day
speak('The current date is')
speak(day)
speak(month)
speak(year)
def wish_me():
speak("Welcome back Ayush!")
time_()
date_()
# greeting
hour = datetime.datetime.now().hour
if hour>=6 and hour<12:
speak("Good Morning Sir!")
elif hour>=12 and hour<18:
speak("Good Afternoon Sir!")
elif hour>=18 and hour<24:
speak("Good Evening Sir!")
else:
speak("Good Night Sir!")
speak("Jarvis at your Service how can i help you")
def send_email(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls() # FOR THIS FUNCTION YOU MUST ENABLE LOW SECURITY IN YOUR GMAIL ACCOUNT
server.login('[email protected]', 'qwerty123@')
server.sendmail('[email protected]', to, content)
server.close()
def cpu():
usage = str(psutil.cpu_percent())
speak('CPU is at' +usage)
battery = psutil.sensors_battery()
speak("battery is ")
speak(battery.percent)
temp = psutil.sensors_temperatures()
speak('current temperature is'+temp)
def Take_command ():
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-US')
print(query)
except Exception as e:
print(e)
print("Sorry can you say it again..........")
return "None"
return query
if __name__ == "__main__":
wish_me()
while True:
query = Take_command().lower()
# All commands will be stored in lower case in query
if 'time' in query: # tell us time when asked
time_()
elif 'date' in query: # Tell us date when asked
date_()
elif 'wikipedia' in query:
speak('searching')
query = query.replace('wikipedia', '')
result = wikipedia.summary(query,sentences=4)
speak('According to Wikipedia')
print(result)
speak(result)
elif 'send mail' in query:
try:
speak('What should i say!')
content = Take_command()
# PROVIDE RECIEVER EMAIL ADDRESS
speak('Who is the Reciever ?')
reciever = input("ENTER RECIEVER'S EMAIL ADDRESS:")
to = reciever
send_email(to,content)
speak(content)
speak('Email has been sent.')
except Exception as e:
print(e)
speak("unable to send Email.")
elif 'search in chrome' in query:
speak('what to search?')
chromepath = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s'
# chromepath stores the chromes location
search = Take_command().lower()
wb.get(chromepath).open_new_tab(search+'.com')
# It only search for websites ending with .com
elif 'search youtube' in query:
speak('what should i search?')
search_term = Take_command().lower()
speak("HERE WE go to YOUTUBE!")
wb.open('https://www.youtube.com/result?search_query='+search_term)
elif 'search google' in query:
speak('what should i search?')
search_term = Take_command().lower()
speak("HERE WE go to GOOGLE!")
wb.open('https://www.google.com/search?q=' + search_term)
elif 'cpu' in query:
cpu()
elif 'joke' in query:
joke()
elif 'go offline' in query:
speak('Going off line sir!')
quit()
elif 'word' in query:
speak('Opening MS Word...')
ms_word = r'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE'
os.startfile(ms_word)
elif 'write a note' in query:
speak('what should i write, sir?')
notes = Take_command()
file = open('note.txt', 'a')
speak('sir should i include Date and time?')
ans = Take_command().lower()
if 'yes' in ans or 'sure' in ans:
strTime =datetime.datetime.now().strftime("%H:%M:%S")
file.write(strTime)
file.write(":-")
file.write(notes)
speak('Done taking notes.')
else:
file.write(notes)
speak('Done taking notes, sir!')
file.close()
elif 'show note' in query:
file = open('note.txt', 'r')
print(file.read())
speak(file.read())
elif 'screenshot' in query:
screenshot()
elif 'play_music' in query:
song_dr = filedialog.askopenfilename()
music = os.listdir(song_dr)
speak('what should i play?')
ans = Take_command().upper()
no = int(ans.replace('number', ''))
os.startfile(os.path.join(song_dr, music[no]))
elif 'remember that' in query:
speak('What should i remember,sir?')
memory =Take_command()
speak('you asked me to remember that'+memory)
remember = open('memory.txt', 'a')
remember.write(memory)
remember.close()
elif 'do you remember anything' in query:
remember =open('memory.txt', 'r')
speak('You asked me to remember that'+remember.read())
remember.close()
elif 'news' in query:
try:
jsonObj = urlopen('http://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=8310479d0e7f473fad636f532b41b8b0')
data = json.load(jsonObj)
i = 1
speak("Here are some top headline from you")
print("==========TOP HEADLINES==========")
for item in data['articles']:
print(str(i)+ ':'+item['title']+'\n')
print(item['description']+'\n\n')
speak(item['title'])
i=i+1
except Exception as e:
print(str(e))
elif 'where is' in query:
location = query.replace("where is","")
speak("you asked me to locate"+ location)
wb.open_new_tab("https://www.google.com/maps/place/"+location)
elif 'calculate' in query:
client = wolframalpha.Client(wolframalpha_app_id)
indx = query.lower().split().index('calculate')
query = query.split()[indx+ 1:]
res = client.query(''.join(query))
answer = next(res.results).text
print('the Answer is :'+answer)
speak('the Answer is :'+answer)
elif 'what is' in query or 'who is ':
client = wolframalpha.Client(wolframalpha_app_id)
res = client.query(query)
try:
print(next(res.results).text)
speak(next(res.results).text)
except StopIteration:
print('no result found!')
speak('No result found!')
elif 'stop listening' in query:
speak('For How many seconds ,sir')
ans = int(Take_command())
time.sleep(ans)
print(ans)
# GIVING COMPUTERS CONTROLS
elif 'log out' in query:
os.system("shutdown -1")
elif 'restart' in query:
os.system("shutdown /r /t 1")
elif 'shutdown' in query:
os.system("shutdown /s /t 1")
else:
speak("SORRY I DON'T KNOW")