Update Jarvis2_4windows.py
This commit is contained in:
parent
ef9defa759
commit
750a84706d
@ -3,14 +3,15 @@ import random
|
|||||||
import smtplib
|
import smtplib
|
||||||
import sys
|
import sys
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
import pyttsx3
|
import pyttsx3
|
||||||
import speech_recognition as sr
|
|
||||||
import wikipedia
|
import wikipedia
|
||||||
from pygame import mixer
|
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
import speech_recognition as sr
|
||||||
|
|
||||||
|
from pygame import mixer
|
||||||
|
|
||||||
mixer.init()
|
mixer.init()
|
||||||
|
|
||||||
@ -18,8 +19,8 @@ engine = pyttsx3.init("sapi5")
|
|||||||
voices = engine.getProperty("voices")
|
voices = engine.getProperty("voices")
|
||||||
engine.setProperty("voice", voices[0].id)
|
engine.setProperty("voice", voices[0].id)
|
||||||
|
|
||||||
def search_engine_selector():
|
|
||||||
|
def search_engine_selector(): # this funcition checks wich search engine is selected in config file.
|
||||||
if config['DEFAULT']['search_engine'] == 'Google':
|
if config['DEFAULT']['search_engine'] == 'Google':
|
||||||
return "https://www.google.com"
|
return "https://www.google.com"
|
||||||
elif config['DEFAULT']['search_engine'] == 'Bing':
|
elif config['DEFAULT']['search_engine'] == 'Bing':
|
||||||
@ -28,8 +29,14 @@ def search_engine_selector():
|
|||||||
return "https://www.duckduckgo.com"
|
return "https://www.duckduckgo.com"
|
||||||
elif config['DEFAULT']['search_engine'] == 'Youtube':
|
elif config['DEFAULT']['search_engine'] == 'Youtube':
|
||||||
return "https://www.youtube.com"
|
return "https://www.youtube.com"
|
||||||
else:
|
else: #If none of default ones selected it tries to use https://{config['DEFAULT']['search_engine'].lower()}.com as search engine.
|
||||||
return f"https://www.{config['DEFAULT']['search_engine'].lower()}.com"
|
#if its a valid url, it returns it as the search engine.
|
||||||
|
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: return "https://www.google.com"
|
||||||
|
|
||||||
def open_url(url):
|
def open_url(url):
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
@ -202,9 +209,9 @@ def main():
|
|||||||
|
|
||||||
speak("Next Command! Sir!")
|
speak("Next Command! Sir!")
|
||||||
|
|
||||||
if os.path.isfile('./config.ini'):
|
if os.path.isfile('./config.ini'): #Checks if config.ini exists.
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser() #if exists loads library.
|
||||||
config.read('config.ini')
|
config.read('config.ini') #and also the file.
|
||||||
main()
|
main() #Then launchs the main program
|
||||||
else:
|
else:
|
||||||
print('You need a config.ini file. Check the documentation in the Github Repository.')
|
print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits.
|
||||||
Loading…
x
Reference in New Issue
Block a user