Update Jarvis2_4windows.py
This commit is contained in:
parent
c216932520
commit
7348f4e23c
@ -16,25 +16,6 @@ MASTER = "Tony Stark"
|
|||||||
engine = pyttsx3.init('sapi5') #
|
engine = pyttsx3.init('sapi5') #
|
||||||
voices = engine.getProperty('voices')
|
voices = engine.getProperty('voices')
|
||||||
engine.setProperty('voice', voices[0].id)
|
engine.setProperty('voice', voices[0].id)
|
||||||
popular_websites = {'google': 'https://www.google.com',
|
|
||||||
'youtube': 'https://www.youtube.com',
|
|
||||||
'wikipedia': 'https://www.wikipedia.org',
|
|
||||||
'amazon': 'https://www.amazon.com'}
|
|
||||||
search_engines = {'google': 'https://www.google.com',
|
|
||||||
'youtube': 'https://www.youtube.com',
|
|
||||||
'bing': 'https://www.bing.com'}
|
|
||||||
|
|
||||||
|
|
||||||
def open_url(url):
|
|
||||||
webbrowser.open(url)
|
|
||||||
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
|
|
||||||
webbrowser.get(chrome_path).open(url)
|
|
||||||
|
|
||||||
def search(search_query, search_engine):
|
|
||||||
try:
|
|
||||||
open_url(f'{search_engines[search_engine]}/search?q={search_query}')
|
|
||||||
except IndexError:
|
|
||||||
open_url(f'https://www.google.com/search?q={search_query}')
|
|
||||||
|
|
||||||
|
|
||||||
def speak(text):
|
def speak(text):
|
||||||
@ -100,18 +81,21 @@ while True:
|
|||||||
'Nice!', 'I am nice and full of energy']
|
'Nice!', 'I am nice and full of energy']
|
||||||
speak(random.choice(stMsgs))
|
speak(random.choice(stMsgs))
|
||||||
|
|
||||||
elif 'open' in query.lower():
|
elif 'open_youtube' in query.lower() or 'youtube' 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 'search' in query.lower():
|
webbrowser.open("youtube.com")
|
||||||
search_query = query.split('for')[-1]
|
url = 'https://www.youtube.com/'
|
||||||
search_engine = query.split('for')[0].replace('search', '').strip().lower()
|
|
||||||
search(search_query, search_engine)
|
chrome_path = 'open -a /Applications/Google/ Chrome.app %s'
|
||||||
|
webbrowser.get(chrome_path).open(url)
|
||||||
|
|
||||||
|
elif 'open_google' in query.lower() or 'google' in query.lower():
|
||||||
|
|
||||||
|
webbrowser.open("google.com")
|
||||||
|
url = 'https://www.google.com/'
|
||||||
|
|
||||||
|
chrome_path = 'open -a /Applications/Google/ Chrome.app %s'
|
||||||
|
webbrowser.get(chrome_path).open(url)
|
||||||
|
|
||||||
elif 'mail' in query:
|
elif 'mail' in query:
|
||||||
speak('Who is the recipient? ')
|
speak('Who is the recipient? ')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user