DesktopAssistant/actions.py

66 lines
1.7 KiB
Python
Raw Normal View History

import datetime
2021-10-07 17:31:11 +02:00
import webbrowser
import pyttsx3
2021-10-07 17:31:11 +02:00
import requests
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
def search_engine_selector(config):
if config['DEFAULT']['search_engine'] == 'Google':
return "https://www.google.com"
elif config['DEFAULT']['search_engine'] == 'Bing':
return "https://www.bing.com"
elif config['DEFAULT']['search_engine'] == 'DuckDuckGo':
return "https://www.duckduckgo.com"
elif config['DEFAULT']['search_engine'] == 'Youtube':
return "https://www.youtube.com"
else:
# If none of default ones selected
try:
if requests.get(
f"https://{config['DEFAULT']['search_engine'].lower()}.com",
params={'q': 'example'}
).status_code == 200:
return (
f"https://{config['DEFAULT']['search_engine'].lower()}.com"
)
else:
return "https://www.google.com"
except Exception as e:
print(e)
return "https://www.google.com"
def open_url(url):
webbrowser.open(url)
chrome_path = r"open -a /Applications/Google\ Chrome.app %s"
webbrowser.get(chrome_path).open(url)
def search(search_query, search_engine):
open_url(f"{search_engine}/search?q={search_query}")
def speak(text):
engine.say(text)
engine.runAndWait()
2021-10-08 18:43:18 +02:00
def wishMe(master):
hour = datetime.datetime.now().hour
# print(hour)
if hour >= 0 and hour < 12:
2021-10-08 18:43:18 +02:00
speak("Good Morning" + master)
elif hour >= 12 and hour < 18:
2021-10-08 18:43:18 +02:00
speak("Good Afternoon" + master)
else:
2021-10-08 18:43:18 +02:00
speak("Good Evening" + master)
# speak("Hey I am Jarvis. How may I help you")