/
romeo.py
395 lines (335 loc) · 12.6 KB
/
romeo.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
import subprocess
import wolframalpha
import pyttsx3
import tkinter
import json
import random
import operator
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import pyjokes
import feedparser
import smtplib
import ctypes
import time
import requests
import shutil
from twilio.rest import Client
from clint.textui import progress
from ecapture import ecapture as ec
from bs4 import BeautifulSoup
import win32com.client as wincl
from urllib.request import urlopen
import smtplib
import webbrowser
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import requests
import winshell as winshell
import wolframalpha
from bs4 import BeautifulSoup
import os
from twilio.rest import Client
listener = sr.Recognizer()
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print('listening.....')
listener.pause_threshold = 1
voice = listener.listen(source)
command = ''
try:
print("Recognizing...")
command = listener.recognize_google(voice, language='en-in')
command = command.lower()
if 'romeo' in command:
command = command.replace('romeo', '')
print(command)
else:
pass
# return command
except:
pass
talk('Unable to Recognize your voice.')
return command
except Exception as e:
print(e)
# talk('some thing wrong')
def alarm():
time=datetime.datetime.now().strftime('%I:%M:%p')
hour = int(datetime.datetime.now().hour)
command=take_command()
if 6<= hour < 8:
while True:
if 'exit' in command:
talk("you are so lazy sir")
exit()
else:
talk(f'please wake up sir. now the time is{time}')
def wishMe():
hour = int(datetime.datetime.now().hour)
if 0 <= hour < 12:
talk("Good Morning Sir !")
elif 12 <= hour < 18:
talk("Good Afternoon Sir !")
else:
talk("Good Evening Sir !")
name = "romeo 1.0"
talk("I am your Assistant")
talk(name)
talk("Please tell me how may I help you")
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
# Enable low security in gmail
server.login('pranto.ahmed89@gmail.com', '*1l0A3#EmI-3#')
server.sendmail('pranto.ahmed89@gmail.com', to, content)
server.close()
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('email address', 'email password')
server.sendmail('email address', to, content)
server.close()
def run_romeo(time=None):
clear = lambda: os.system('cls')
# This Function will clean any
# command before execution of this python file
clear()
command = take_command()
print(command)
name = "romeo 1.0"
if 'play ' in command or 'playing ' in command:
try:
song = command.replace('play', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
except Exception as e:
print(e)
talk(f"unable to find this {song} in youtube")
elif 'time' in command or 'what time is it ' in command:
time = datetime.datetime.now().strftime('%I:%M:%p') # I is the formate of the time and p is the am or pm
print(time)
talk('current time is ' + time)
elif 'tell me about ' in command:
try:
person = command.replace('tell me about', '')
info = wikipedia.summary(person, 2)
# print(info)
talk(f'according to wikipedia {info}')
except Exception as e:
print(e)
talk(f"unable to find this wikipedia{info} ")
elif 'joke' in command:
talk(' here you go')
talk(pyjokes.get_joke())
elif 'what is the date ' in command or 'date' in command:
date = datetime.date.today()
talk(date)
elif '.com' in command or '.org' in command or '.net' in command or ' search' in command:
try:
web = command.replace('.com', '').replace('.org', '').replace('.net', '').replace('search', '').replace(
'romeo', '')
talk(web)
print(web)
# talk(command)
webbrowser.open_new_tab(web)
# webbrowser.open("youtube.com")
except Exception as e:
print(e)
talk(f"unable to search {web} ")
elif 'my audio music' in command or "start my audio music" in command:
talk("why not sir ,Here you go with music")
# music_dir = "G:\\Song"
music_dir = "C:\\Users\\Public\\Music"
songs = os.listdir(music_dir)
print(songs)
random = os.startfile(os.path.join(music_dir, songs[1]))
elif 'how are you' in command:
talk("I am fine, Thank you")
talk("How are you, Sir")
elif 'fine' in command or "good" in command:
talk("It's good to know that your fine")
elif "change my name to" in command:
query = command.replace("change my name to", "")
name = command
elif "change name" in command:
talk("What would you like to call me, Sir ")
name = take_command()
talk("Thanks for naming me")
elif "who made you" in command or "who created you" in command:
talk("it is greate to know you that I have been created by my boss.")
elif "why you came to world" in command:
talk("Thanks to my boss. further It's a secret ")
elif 'open microsoft office' in command:
talk("opening Power Point presentation")
power = r"C:\\Program Files (x86)\\Microsoft Office\\Office15"
os.startfile(power)
elif 'what is love' in command or 'tell me about love' in command:
talk("It is 7th sense that destroy all other senses..it's a crazy things is not it my friend")
elif "who are you" in command:
talk(f"I am your virtual assistant {name}")
elif "can you hear me" in command or "are you there" in command:
talk('yes sir ,please tell me how can i help you ,do you need anything sir')
elif 'open bluestack' in command:
appli = r"C:\\ProgramData\\BlueStacks\\Client\\Bluestacks.exe"
os.startfile(appli)
elif 'empty recycle bin' in command:
winshell.recycle_bin().empty(confirm=False, show_progress=False, sound=True)
talk("Recycle Bin Recycled")
elif "don't listen" in command or "stop listening" in command:
try:
talk("for how much time you want to stop jarvis from listening commands")
a = int(take_command())
time.sleep(a)
print(a)
except Exception:
talk("i don't listen you ")
elif "where is" in command or "romeo where is" in command or " romeo search where is" in command:
try:
query = command.replace("where is", "").replace("romeo where is", " ").replace("romeo search where is", " ")
location = query
talk("User asked to Locate")
talk(location)
webbrowser.open("https://www.google.com/maps/place/" + location + "")
except Exception:
talk('not found this place')
elif "weather" in command:
# Google Open weather website
# to get API of Open weather
api_key = "api key"
# base_url = "http://api.openweathermap.org / data / 2.5 / weather?"
talk(" City name ")
print("City name : ")
city_name = take_command()
# complete_url = base_url + "appid =" + api_key + "&q =" + city_name
complete_url = f"https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}"
response = requests.get(complete_url)
x = response.json()
if x["cod"] != "404":
y = x["main"]
current_temperature = y["temp"]
current_pressure = y["pressure"]
current_humidiy = y["humidity"]
z = x["weather"]
weather_description = z[0]["description"]
print(" Temperature (in kelvin unit) = " + str(
current_temperature) + "\n atmospheric pressure (in hPa unit) =" + str(
current_pressure) + "\n humidity (in percentage) = " + str(
current_humidiy) + "\n description = " + str(weather_description))
else:
talk(" City Not Found ")
elif 'open code' in command:
codePath = "/Applications/PyCharm CE.app" # that's the code path.
os.startfile(codePath)
elif "calculate" in command or 'i want to know ' in command:
try:
# command = command.replace('calculate', '').replace('how to', '').replace('i want to know', '')
query = command.replace('calculate', '').replace('i want to know', '')
app_id = "Wolframalpha api id"
# client = wolframalpha.Client(app_id)
client = wolframalpha.Client('app_id')
question = query
res = client.query(question)
answer = next(res.results).text
print("The answer is " + answer)
talk("The answer is " + answer)
except Exception as e:
print(e)
talk('sorry sir i am not able to do this,please try again')
elif "camera" in command or "take a photo" in command:
try:
ec.capture(0, "robo camera", "img.jpg")
except Exception:
talk('photos are not taken')
elif 'email to gm' in command:
try:
talk('What is the subject?')
subject = take_command()
talk('What should I say in message?')
message = take_command()
content = 'Subject: {}\n\n{}'.format(subject, message)
to = "golam.mahmud99@gmail.com"
sendEmail(to, content)
talk("Email has been sent!")
except Exception as e:
print(e)
talk("Sorry my friend. I am not able to send this email")
elif 'send a mail' in command:
try:
talk("What should I say?")
content = take_command()
talk("whome should i send")
to = input()
sendEmail(to, content)
talk("Email has been sent !")
except Exception as e:
print(e)
talk("I am not able to send this email")
elif "write a note" in command:
try:
talk("What should i write, sir")
note = take_command()
file = open('jarvis.txt', 'w')
talk("Sir, Should i include date and time")
snfm = take_command()
if 'yes' in snfm or 'sure' in snfm:
strTime = datetime.datetime.now().strftime("% H:% M:% S")
file.write(strTime)
file.write(" :- ")
file.write(note)
else:
file.write(note)
except Exception:
talk('i am not able to write this note sir')
# elif "what is" in command or "who is" in command:
#
# # Use the same API key
# # that we have generated earlier
# client = wolframalpha.Client("API_ID")
# res = client.query(command)
#
# try:
# print(next(res.results).text)
# talk(next(res.results).text)
# except StopIteration:
# print("No results")
elif 'why are you answer so slow' in command or 'tell me why are you so slow' in command:
talk('sir this is not my fault .your internet connection is so slow now')
elif 'exit' in command:
try:
talk("Thanks for giving me your time")
exit()
except Exception as e:
print(e)
talk('i am not able to exit sir ..something doing wrong')
elif 'what is the temperature in' in command:
try:
search=command.replace('what is the temperature in','')
url = f'https://www.google.com/search?q={search}'
r = requests.get(url)
data = BeautifulSoup(r.text, 'html.parser')
temp = data.find("div", class_='BNeawe').text
talk(f'current {search} is {temp}')
except Exception as e:
print(e)
talk('i am not able to find this place temperature ')
if __name__ == '__main__':
wishMe()
while True:
run_romeo()