Update Jarvis2.py

This commit is contained in:
B.Jothin kumar 2021-10-08 12:30:04 +05:30 committed by GitHub
parent 2f2077a868
commit 935415f8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,8 @@ import pyttsx3
import speech_recognition as sr
import wikipedia
import gui
print("Initializing Jarvis....")
MASTER = getpass.getuser()
@ -46,6 +48,7 @@ def search(search_query, search_engine):
def speak(text):
gui.speak(text)
engine.say(text)
engine.runAndWait()
@ -95,79 +98,86 @@ def take_command():
speak("Initializing Jarvis....")
wish_me()
query = take_command().lower()
# logic for executing basic tasks
if "wikipedia" in query.lower():
speak("Searching wikipedia....")
query = query.replace("wikipedia", "")
print_and_speak(wikipedia.summary(query, sentences=2))
elif "what's up" in query or "how are you" in query:
st_msgs = (
"Just doing my thing!",
"I am fine!",
"Nice!",
"I am nice and full of energy",
)
speak(random.choice(st_msgs))
def execute_the_command_said_by_user():
query = take_command().lower()
elif "date" in query:
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
# logic for executing basic tasks
if "wikipedia" in query:
speak("Searching wikipedia....")
query = query.replace("wikipedia", "")
print_and_speak(wikipedia.summary(query, sentences=2))
elif "time" in query:
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
elif "what's up" in query or "how are you" in query:
st_msgs = (
"Just doing my thing!",
"I am fine!",
"Nice!",
"I am nice and full of energy",
)
speak(random.choice(st_msgs))
elif "open" in query.lower():
website = query.replace("open", "").strip().lower()
try:
open_url(popular_websites[website])
except IndexError: # If the website is unknown
print(f"Unknown website: {website}")
speak(f"Sorry, I don't know the website {website}")
elif "date" in query:
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
elif "search" in query.lower():
search_query = query.split("for")[-1]
search_engine = query.split("for")[0].replace("search", "").strip().lower()
search(search_query, search_engine)
elif "time" in query:
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
elif "email" in query:
speak("Who is the recipient? ")
recipient = take_command()
if "me" in recipient:
elif "open" in query.lower():
website = query.replace("open", "").strip().lower()
try:
speak("What should I say? ")
content = take_command()
open_url(popular_websites[website])
except IndexError: # If the website is unknown
print(f"Unknown website: {website}")
speak(f"Sorry, I don't know the website {website}")
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login("Your_Username", "Your_Password")
server.sendmail("Your_Username", "Recipient_Username", content)
server.close()
speak("Email sent!")
except Exception:
speak("Sorry Sir! I am unable to send your message at this moment!")
elif "search" in query.lower():
search_query = query.split("for")[-1]
search_engine = query.split("for")[0].replace("search", "").strip().lower()
search(search_query, search_engine)
elif "nothing" in query or "abort" in query or "stop" in query:
speak("okay")
speak("Bye Sir, have a good day.")
sys.exit()
elif "email" in query:
speak("Who is the recipient? ")
recipient = take_command()
elif "hello" in query:
speak("Hello Sir")
if "me" in recipient:
try:
speak("What should I say? ")
content = take_command()
elif "bye" in query:
speak("Bye Sir, have a good day.")
sys.exit()
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login("Your_Username", "Your_Password")
server.sendmail("Your_Username", "Recipient_Username", content)
server.close()
speak("Email sent!")
except Exception:
speak("Sorry Sir! I am unable to send your message at this moment!")
elif "play music" in query:
music_folder = "Your_music_folder_path(absolute_path)"
music = ("music1", "music2", "music3", "music4", "music5")
random_music = music_folder + random.choice(music) + ".mp3"
os.system(random_music)
elif "nothing" in query or "abort" in query or "stop" in query:
speak("okay")
speak("Bye Sir, have a good day.")
sys.exit()
speak("Playing your request")
elif "hello" in query:
speak("Hello Sir")
speak("Next Command! Sir!")
elif "bye" in query:
speak("Bye Sir, have a good day.")
sys.exit()
elif "play music" in query:
music_folder = "Your_music_folder_path(absolute_path)"
music = ("music1", "music2", "music3", "music4", "music5")
random_music = music_folder + random.choice(music) + ".mp3"
os.system(random_music)
speak("Playing your request")
speak("Next Command! Sir!")
gui.set_speak_command(execute_the_command_said_by_user)
gui.mainloop()