This commit is contained in:
TallGorilla 2021-10-07 16:07:05 +02:00
commit 66ab2a5cad
3 changed files with 128 additions and 68 deletions

View File

@ -11,7 +11,7 @@ jobs:
flake8-comprehensions isort mypy pytest pyupgrade safety
- run: bandit --recursive --skip B311,B605 .
- run: black --check . || true
- run: codespell
- run: codespell --ignore-words-list=ans
- run: flake8 . --count --max-complexity=19 --max-line-length=88 --show-source --statistics
- run: isort --check-only --profile black .
- run: pip install -r requirements.txt || pip install --editable . || true

View File

@ -20,8 +20,7 @@ voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
# this funcition checks wich search engine is selected in config file.
def search_engine_selector():
def search_engine_selector(): # this funcition checks which search engine is selected in config file.
if config['DEFAULT']['search_engine'] == 'Google':
return "https://www.google.com"
elif config['DEFAULT']['search_engine'] == 'Bing':
@ -30,38 +29,27 @@ def search_engine_selector():
return "https://www.duckduckgo.com"
elif config['DEFAULT']['search_engine'] == 'Youtube':
return "https://www.youtube.com"
else:
# If none of default ones selected
else: #If none of default ones selected it tries to use https://{config['DEFAULT']['search_engine'].lower()}.com as search engine.
#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 Exception as e:
print(e)
return "https://www.google.com"
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):
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()
def wishMe(MASTER):
hour = datetime.datetime.now().hour
# print(hour)
@ -76,7 +64,6 @@ def wishMe(MASTER):
# speak("Hey I am Jarvis. How may I help you")
def main():
MASTER = config['DEFAULT']['MASTER']
@ -99,29 +86,29 @@ def main():
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening....")
if debug == "True":print("Listening....")
else:pass
r.pause_threshold = 0.5
audio = r.listen(source)
query = " "
try:
print("Recognizing....")
if debug == "True":print("Recognizing....")
else:pass
query = r.recognize_google(audio, language="en-in")
print("user said: " + query)
if debug == "True":print("user said: " + query)
else:pass
except sr.UnknownValueError:
if debug == "True":
print("Sorry Could You please try again")
else:
pass
if debug == "True":print("Sorry Could You please try again")
else:pass
speak("Sorry Could You please try again")
except Exception as e:
if debug == "True":
print(e)
print("Say That Again Please")
else:
pass
else:pass
query = None
return query
@ -136,10 +123,8 @@ def main():
speak("Searching wikipedia....")
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
if debug == "True":
print(results)
else:
pass
if debug == "True":print(results)
else:pass
speak(results)
elif "what's up" in query or "how are you" in query:
@ -156,10 +141,8 @@ def main():
try:
open_url(popular_websites[website])
except KeyError: # If the website is unknown
if debug == "True":
print(f"Unknown website: {website}")
else:
pass
if debug == "True":print(f"Unknown website: {website}")
else:pass
speak(f"Sorry, i don't know the website {website}")
speak(f"¿Do you want me to search {website} in the web?")
if takeCommand() == "yes":
@ -167,6 +150,7 @@ def main():
else:
pass
elif "search" in query.lower():
search_query = query.split("for")[-1]
search(search_query, search_engine)
@ -180,17 +164,15 @@ def main():
speak("What should I say? ")
content = takeCommand()
email = config['EMAIL']
server = smtplib.SMTP(email['server'], email['port'])
server = smtplib.SMTP(config['EMAIL']['server'], config['EMAIL']['port'])
server.ehlo()
server.starttls()
server.login(email['username'], email['password'])
server.sendmail(email['username'], recipient, content)
server.login(config['EMAIL']['username'], config['EMAIL']['password'])
server.sendmail(config['EMAIL']['username'], recipient, content)
server.close()
speak("Email sent!")
except Exception:
speak("Sorry Sir!")
speak("I am unable to send your message at this moment!")
speak("Sorry Sir! I am unable to send your message at this moment!")
elif "nothing" in query or "abort" in query or "stop" in query:
speak("okay")
@ -215,6 +197,7 @@ def main():
except Exception as e:
speak(e)
elif "pause music" in query:
mixer.music.pause()
@ -226,12 +209,9 @@ def main():
speak("Next Command! Sir!")
if os.path.isfile('./config.ini'): #Checks if config.ini exists.
config = configparser.ConfigParser() #if exists loads library.
config.read('config.ini') #and also the file.
main() # Then launchs the main program
main() #Then launches the main program
else:
# if it doesn't exist it drops an error message and exits.
print('You need a config.ini file.')
print('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.

80
run.md Normal file
View File

@ -0,0 +1,80 @@
# How to run the program
Here are some installation Guidelines and procedure how you can execute the programme and use it for performing basic tasks:
## Table of Contents:
- [Check for `PIP` installation](#check-for-pip-installation)
- [Pyttsx3](#pyttsx3)
- [Speech Recognition](#speech-recognition)
- [Pygame <br>](#pygame-)
- [Suitable IDE for running this program](#suitable-ide-for-running-this-program)
- [Commands to interact with program.](#commands-to-interact-with-program)
-------------------------------------
## Check for `PIP` installation
- PIP is a tool that is used to install python packages. PIP is automatically installed with Python 2.7. 9+ and Python 3.4+.
- Open the command prompt and enter the below command to check whether pip is installed.
```md
pip --version
```
- If you are receiving an error, it means that you might be having `pip3` installed, so try this command.
```md
pip3 --version
```
```md
python --version
```
> If you are still facing issues, try installing pip from [here](https://github.com/pypa/pip#readme)
## Pyttsx3
<!-- Pyttsx3 -->
- pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3
- Open the command prompt/terminal and enter the below command to install `pyttsx3`
```md
pip install pyttsx3
```
> Visit the [Pyttsx3 documentation](https://pypi.org/project/pyttsx3/) to know more about this library.
## Speech Recognition
- SpeechRecognition is a library for performing speech recognition, with support for several engines and APIs, online and offline.
- Open the command prompt/terminal and enter the below command to install `SpeechRecognition`
```md
pip install SpeechRecognition
```
> Visit the [Speech Recognition documentation](https://pypi.org/project/SpeechRecognition/) to know more about this library.
<!-- pygame -->
## Pygame <br>
- Pygame is a set of Python modules designed for writing video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language.
- Open the command prompt/terminal and enter the below command to install `Pygame`
```md
pip install pygame
```
# Suitable IDE for running this program
- Desktop Assistant can be run in the following Code editoe IDEs.
- [Pycharm](https://www.jetbrains.com/help/pycharm/installation-guide.html)
- [VS Code](https://code.visualstudio.com/docs)
- [Jupyter-lab](https://jupyterlab.readthedocs.io/en/latest/)
- [Replit](https://docs.replit.com/)
# Commands to interact with program.
After successful installation of the forementioned dependencies, you can use the following commands (speak out) to interact with Jarvis, your `Desktop-Assistant`
```
Start with : Hello
Random Ans : How are you?
: Google
: Youtube
send email : Open email
: Nothing
: Abort
: Stop
End with : Bye
```