-
Notifications
You must be signed in to change notification settings - Fork 0
/
eric.py
352 lines (273 loc) · 11.1 KB
/
eric.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
import sys
import time
from bs4 import BeautifulSoup
import self
import math
import instaloader
import pyttsx3
import requests
import speech_recognition as sr
import datetime
import os
import cv2
import random
import wikipedia
from requests import get
import webbrowser
import pywhatkit as kit
import smtplib
import pyjokes
import pyautogui
import datetime
from playsound import playsound
import psutil
import speedtest
import PyPDF2
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[1].id)
engine.setProperty('voices', voices[1].id)
'''voices[0].id gives the voice of TTS_MS_EN-US_DAVID_11.0
if voices[1] is there then it will gives the voice of TTS_MS_EN-US_ZIRA_11.0 '''
# Text to speech
def speak(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
# To convert voice to text
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 3
audio = r.listen(source, timeout=3, phrase_time_limit=5)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}")
except Exception as e:
speak("Say that again please...")
return "none"
return query
# To wish
def wish():
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 Eric. Please tell me how can I help you")
#SEND MESSAGES ON WHATSAPP
def whatsapp_msg():
speak("To whom you want to send the message?")
name = takecommand()
number = whatsapp_contact[name]
speak(f"what message you want to send to {name} ")
content = takecommand()
speak("set the time ,in what time you want to send the message. set the time in 24 hour format")
kit.sendwhatmsg(f"+91{number}", f"{content}", int(input()), int(input()))
# kit.sendwhatmsg("+917781041625", "Hi this message is sent by a desktop assistant", 13,30,00)
speak("Your message is sent")
whatsapp_contact = {
'Sonal': '7781041625',
'Tejaswini': '9307405066',
'Anvi': '9822695617',
'Janvi': '9146226162'
}
#Fetch NEWS ----------- WORKING
def news():
# take a news from newsapi.org
main_url = 'http://newsApi.org/v2/top-headlines?sources=techcrunch&apiKey=e455b81623214aeabb34eeac5e8c489d'
# print(main_page)
main_page = requests.get(main_url).json()
# store articles in variable
article = main_page["articles"]
# empty list
head = []
day = ["first", "second", "third", "fourth", "fifth"]
for ar in article:
head.append(ar["title"])
for i in range(len(day)):
speak(f"today's {day[i]} news is: {head[i]}")
if __name__ == "__main__":
wish()
while True:
query = takecommand().lower()
# Logic building for tasks
#OPEN NOTEPAD WORKS
if "open notepad" in query:
npath = "C:\\windows\\system32\\notepad.exe"
os.startfile(npath)
# To close notepad
elif "Close notepad" in query:
speak("Closing Notepad.")
os.sys("taskkill /f /im notepad.exe")
elif "open adobe reader" in query:
apath = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe"
os.startfile(apath)
# Open different editors by os module ---- ***
elif "open Editor" in query:
speak("Which editor you want to open ?")
editor = takecommand().lower()
if "vs code" in editor:
path = "C:\Program Files\Microsoft VS Code\Code.exe"
os.startfile(path)
elif "pycharm" in editor:
path = "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1\bin\pycharm64.exe"
os.startfile(path)
elif "open command prompt" in query:
# open command prompt by os module
os.system("start cmd")
elif "open skype" in query:
path = "C:\Program Files\Microsoft Office\root\Office16\SkypeSrv\SKYPESERVER.EXE"
os.startfile(path)
# To open camera
elif "open camera" in query:
cap = cv2.VideoCapture(0)
while True:
ret, img = cap.read()
cv2.imshow('webcam', img)
k = cv2.waitKey(50)
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
# To find ip address
elif "ip address" in query:
ip = get('https://api.ipify.org').text
speak(f"your IP address is {ip}")
# To search Wikipedia
elif "wikipedia" in query:
speak("Searching Wikipedia")
query = query.replace("wikipedia", " ")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
speak(results)
print(results)
#OPEN DIFFERENT SITES
# Social browsing
elif "open facebook" in query:
webbrowser.open("www.facebook.com")
elif "open twitter" in query:
webbrowser.open("www.twitter.com")
elif "open instagram" in query:
webbrowser.open("www.instagram.com")
elif "open stackoverflow" in query:
webbrowser.open("www.stackoverflow.com")
elif "search on google" in query:
speak("What should i search on google")
search = takecommand().lower()
webbrowser.open(f"{search}")
#Sending msg on different social media platform
elif "send message" in query:
whatsapp_msg()
elif "who am I" in query:
speak("If you talk then definitely you are a human.")
# Play music on youtube
elif "play music on youtube" in query:
speak("which song you want to listen on youtube")
song_name = takecommand().lower()
kit.playonyt(f"{song_name}")
# To close any application *****
elif "close notepad" in query:
speak("okay, closing notepad")
os.system("taskkill /f /im notepad.exe")
# To shut down the system
elif "shut down the system" in query:
os.system("shutdown /s /t 5")
# To restart the system -- works
elif "restart the system" in query:
os.system("shutdown /r /t 5")
# To sleep the system
elif "sleep the system" in query:
os.system("rundll32.exe powrprof.dil,SetSuspendState 0,1,0")
# Switch the tab or window
elif "Switch the window" in query:
pyautogui.keyDown("alt")
pyautogui.press("tab")
time.sleep(1)
pyautogui.keyUp("alt")
# Tell the news - first fetch the online data then convert it in list then by for loop it iterate then gives the
# headlines
elif "tell the news" in query:
speak("please wait, fetching the latest news")
news()
# Location ------- ****
elif "Where am I ?" in query or "Where are we ?" in query:
speak("wait, let me check")
try:
ip_add = requests.get('https://api.ipify.org').text
print(ip_add)
url = 'https://get.geojs.io/v1/ip/geo' + ip_add + '.json'
geo_requests = requests.get(url)
# Scrap the data in json and in json it is in form of dict.
geo_data = geo_requests.json()
# print(geo_data)
city = geo_data['city']
# state = geo_data['state]
country = geo_data['country']
speak(f"I think we are in {city} city of {country} country")
except Exception as e:
speak("Sorry , Due to network problem I am not able to find where we are")
My_location()
# To download instagram profile photo
elif "instagram profile" in query or "insta profile" in query:
speak("Please enter the username correctly")
name = input("Enter the name: ")
webbrowser.open(f"www.instagram.com/{name}")
time.sleep(5)
speak("Would you like to download the profile picture of this account.")
condition = takecommand().lower()
if "yes" in condition:
mod = instaloader.Instaloader()
mod.download_profile(name, profile_pic_only=True)
speak("Task is done, profile picture is saved in our main folder")
else:
pass
# # To take a screenshot
elif "take screenshot" in query or "take a screenshot" in query:
speak("Please tell me the name for this screenshot file")
name = takecommand().lower()
speak("Please hold the screen for few seconds , I am taking the screenshot")
img = pyautogui.screenshot(f"{name}.png")
speak("Task is done, the screenshot is saved in our main folder")
# # To stop JARVIS
elif "You can sleep now" in query:
speak("Thank you for using me. Have a good day.")
sys.exit()
elif 'volum up' in query:
pyautogui.press("volumeup")
elif 'volume down' in query:
pyautogui.press("volumedown")
elif 'mute' in query:
pyautogui.press("volumemute")
elif "how much power left" in query or "how much power we have" in query or "battery" in query:
battery = psutil.sensors_battery()
percentage = battery.percent
speak(f"our system has{percentage}percent battery " )
elif 'temperature' in query:
search = "temperature in Nagpur"
url = f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
teep = data.find("div",class_="BNeawe").text
speak(f"current{search} is {teep}")
elif "internet speed" in query:
st = speedtest.Speedtest()
dl = st.download()
up = st.upload()
speak(f"we have{dl} mb per second downloading speedand {up} mb per second uploading speed")
elif "read pdf" in query:
pdf_reader()
def pdf_reader():
book = open('Greedy Algorithm.pdf','rb')
pdfReader = PyPDF2.PdffileReader(book)
pages = pdfReader.numPages
speak(f"Total number of pages in this PDF is{pages} ")
speak("please enter the page number I have to Read")
pg = int(input("please enter the page number: "))
page = pdfReader.getPage(pg)
text = page.extractText()
speak(text)