-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiris.py
More file actions
344 lines (276 loc) · 10.8 KB
/
iris.py
File metadata and controls
344 lines (276 loc) · 10.8 KB
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
from ntpath import join
from pickle import APPEND
from urllib.request import urlopen
import newsapi
import pyttsx3
import datetime
from pywhatkit.help import exceptions
import speech_recognition as sr
import smtplib
from secrets import senderemail,epwd,to
import pyautogui
import webbrowser as wb
from time import sleep
import wikipedia
import pywhatkit
import clipboard
import requests
import os
import pyjokes
import time as tt
import string
import random
import psutil
import subprocess
import json
from nltk.tokenize import word_tokenize
from newsapi import NewsApiClient
import ctypes
import time
engine=pyttsx3.init()
def speak(audio):
engine.say(audio)
engine.runAndWait()
def getvoices(voice):
voices=engine.getProperty('voices')
#print(voices[1].id)
if voice==1:
engine.setProperty('voice',voices[0].id)
speak("Welcome back !")
speak("Nyx at your service, please tell me how can i help you?")
if voice==2:
engine.setProperty('voice',voices[1].id)
speak("Welcome back !")
speak("Jack at your service, please tell me how can i help you?")
def time():
Time=datetime.datetime.now().strftime("%I:%M:%S")
speak("the current time is:")
speak(Time)
def date():
year=int(datetime.datetime.now().year)
month=int(datetime.datetime.now().month)
date=int(datetime.datetime.now().day)
speak("the current date is:")
speak(date)
speak(month)
speak(year)
def greeting():
hour=datetime.datetime.now().hour
if hour >=6 and hour <12:
speak("Good morning !")
elif hour >= 12 and hour <18:
speak(" Good afternoon !")
elif hour >= 18 and hour <24:
speak(" Good evening !")
else:
speak(" Good Night !")
def wishme():
greeting()
speak("Welcome back !")
speak("Jack at your service, please tell me how can i help you?")
#wishme()
# while True:
# voice=int(input("press 1 for male assistant\npress 2 for female assistant\n"))
# speak(audio)
#getvoices(voice)
def takeCommandCMD():
query=input("Please Tell Me how can i help you?\n")
return query
def takeCommandMic():
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("Pardon Please")
return "None"
return query
def sendEmail(content):
server=smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(senderemail,epwd)
server.sendmail(senderemail,to, content)
server.close()
def searchgoogle():
speak("what should i serach for?")
search=takeCommandMic()
wb.open('https://www.google.com/search?q='+search)
def sendwhatsmsg(phone_no, message):
Message = message
wb.open('https://web.whatsapp.com/send?phone='+phone_no+'&text='+Message)
sleep(10)
pyautogui.press('enter')
def text2speech():
text = clipboard.paste()
print(text)
speak(text)
def screenshot():
name_img= tt.tt()
name_img = f'A:\\jarvis\\Screenshots\\screenshot\\{name_img}.png'
img = pyautogui.screenshot(name_img)
img.show()
def passwordgen():
s1 = string.ascii_uppercase
s2 = string.ascii_lowercase
s3 = string.digits
s4 = string.punctuation
passlen = 8
s = []
s.extend(list(s1))
s.extend(list(s2))
s.extend(list(s3))
s.extend(list(s4))
random.shuffle(s)
newpass = ("".join(s[0:passlen]))
print(newpass)
speak(newpass)
def cpu():
usage = str(psutil.cpu_percent())
speak('cpu is at'+usage)
battery = psutil.sensors_battery()
speak("Battery is at")
speak(battery.percent)
if __name__=="__main__":
getvoices(1)
wakeword= "jack"
while True:
query = takeCommandMic().lower()
query=word_tokenize(query)
if wakeword in query:
if 'time' in query:
time()
elif 'date' in query:
date()
elif 'wish' in query:
greeting()
elif 'email' in query:
try:
speak('what should i say')
content=takeCommandMic()
sendEmail(content)
speak("email has been sent")
except Exception as e:
print(e)
speak("unable to send email")
elif 'message' in query:
user_name={
'Nick':'+91 7975471268'
}
try:
speak("To Whom you want to send the watsapp message?")
name= takeCommandMic()
phone_no = user_name[name]
speak("What is the message?")
message=takeCommandMic()
sendwhatsmsg(phone_no,message)
speak("Whatsapp Message Has beeen Sent")
except Exception as e:
print(e)
speak("Unable to send the message")
elif 'wikipedia' in query:
speak('Searching On Wikipedia...')
query = query.replace("Wikipedia","")
result = wikipedia.summary(query, sentences=2)
print(result)
speak(result)
elif 'search' in query:
searchgoogle()
elif 'youtube' in query:
speak("what should i search for youtube")
topic=takeCommandMic()
pywhatkit.playonyt(topic)
elif 'weather' in query or 'climate' in query:
city='bangalore'
url=f'https://api.openweathermap.org/data/2.5/weather?q={city}&units=imperial&appid=d916f738b8c56aa3b5180f0625025c35'
res=requests.get(url)
data=res.json()
weather=data['weather'][0]['id']
temp=data['main']['temp']
desp=data['weather'][0]['description']
temp=round((temp-32)*5/9)
print(weather)
print(temp)
print(desp)
speak(f'weather in {city} city is like')
speak('Temperature : {} degree celcius'.format(temp))
speak('weather is {}'.format(desp))
elif 'news' in query:
try:
jsonObj = urlopen('''https://newsapi.org/v1/articles?source=the-times-of-india&sortBy=top&apiKey=ce6e2cf8d71a4ef78cdc8cefe6f3b286''')
data = json.load(jsonObj)
i = 1
speak('here are some top news')
print(''' TIMES OF INDIA '''+ '\n')
for item in data['articles']:
print(str(i) + '. ' + item['title'] + '\n')
print(item['description'] + '\n')
speak(str(i) + '. ' + item['title'] + '\n')
i += 1
except Exception as e:
print(str(e))
elif 'read' in query:
text2speech()
elif 'covid' in query:
jsonObj = urlopen('https://coronavirus-19-api.herokuapp.com/all')
data = json.load(jsonObj)
speak('Covid Updates')
# for item in data['data']:
speak("deaths"+str(data['deaths']) + '\n')
speak("cases"+str(data['cases']) + '\n')
speak("recovered"+ str(data['recovered']) + '\n')
elif 'lock' in query:
speak("locking the device")
ctypes.windll.user32.LockWorkStation()
elif 'open' in query:
os.system('explorer C://{}'.format(query.replace('open','')))
elif ' code' in query:
codepath='C:\\Users\\91829\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Python 3.8'
os.startfile(codepath)
elif 'joke' in query:
speak(pyjokes.get_joke())
elif 'screenshot' in query:
screenshot()
elif 'remember' in query:
speak("what should i remember?")
data= takeCommandMic()
speak("you asked me to remember that"+data)
remember =open('data.txt','w')
remember.write(data)
remember.close()
elif 'know' in query:
remember=open('data.txt','r')
speak("you told me to remember that"+remember.read())
elif 'password' in query:
passwordgen()
elif 'stackoverflow' in query or 'stack overflow' in query:
speak("Here you go. Happy coding")
wb.open("https://stackoverflow.com")
elif 'depressed' in query or 'sad' in query or 'depression' in query:
speak(" Feeling down from time to time is a normal part of life. No matter how hopeless you feel, you can get better. ")
speak(" Talk to a doctor or counselor about how you’re feeling.")
speak("Do want to listen to your favourite songs?")
wb.open("https://www.youtube.com/watch?v=1ZYbU82GVz4")
print(" You Got This mate")
elif 'how are you' in query:
speak("I am fine, Thank you")
speak("How are you?")
elif 'cpu' in query:
cpu()
elif 'shut down' in query:
speak("Hold On! Your system is shutting down")
subprocess.call('shutdown / p /f')
elif "restart" in query:
subprocess.call(["shutdown", "/r"])
elif 'made' in query:
speak("TEAM Optimize Prime - For REVA Hack 2021")
print("TEAM Optimize Prime - For REVA Hack 2021")
elif 'goodbye' in query:
speak("Jack logging off")
speak("thank you for giving me your time")
quit()