Merge branch 'main' of https://github.com/TallGorilla/DesktopAssitant
This commit is contained in:
commit
66ab2a5cad
2
.github/workflows/lint_python.yml
vendored
2
.github/workflows/lint_python.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
|||||||
flake8-comprehensions isort mypy pytest pyupgrade safety
|
flake8-comprehensions isort mypy pytest pyupgrade safety
|
||||||
- run: bandit --recursive --skip B311,B605 .
|
- run: bandit --recursive --skip B311,B605 .
|
||||||
- run: black --check . || true
|
- 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: flake8 . --count --max-complexity=19 --max-line-length=88 --show-source --statistics
|
||||||
- run: isort --check-only --profile black .
|
- run: isort --check-only --profile black .
|
||||||
- run: pip install -r requirements.txt || pip install --editable . || true
|
- run: pip install -r requirements.txt || pip install --editable . || true
|
||||||
|
|||||||
@ -20,8 +20,7 @@ voices = engine.getProperty("voices")
|
|||||||
engine.setProperty("voice", voices[0].id)
|
engine.setProperty("voice", voices[0].id)
|
||||||
|
|
||||||
|
|
||||||
# this funcition checks wich search engine is selected in config file.
|
def search_engine_selector(): # this funcition checks which search engine is selected in config file.
|
||||||
def search_engine_selector():
|
|
||||||
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':
|
||||||
@ -30,52 +29,40 @@ 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.
|
||||||
# If none of default ones selected
|
#if its a valid url, it returns it as the search engine.
|
||||||
try:
|
try:
|
||||||
if requests.get(
|
if requests.get(f"https://{config['DEFAULT']['search_engine'].lower()}.com", params= {'q':'example'}).status_code == 200:
|
||||||
f"https://{config['DEFAULT']['search_engine'].lower()}.com",
|
return 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"
|
|
||||||
|
|
||||||
|
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)
|
||||||
chrome_path = r"open -a /Applications/Google\ Chrome.app %s"
|
chrome_path = r"open -a /Applications/Google\ Chrome.app %s"
|
||||||
webbrowser.get(chrome_path).open(url)
|
webbrowser.get(chrome_path).open(url)
|
||||||
|
|
||||||
|
|
||||||
def search(search_query, search_engine):
|
def search(search_query, search_engine):
|
||||||
open_url(f"{search_engine}/search?q={search_query}")
|
open_url(f"{search_engine}/search?q={search_query}")
|
||||||
|
|
||||||
|
|
||||||
def speak(text):
|
def speak(text):
|
||||||
engine.say(text)
|
engine.say(text)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
|
|
||||||
|
|
||||||
def wishMe(MASTER):
|
def wishMe(MASTER):
|
||||||
hour = datetime.datetime.now().hour
|
hour = datetime.datetime.now().hour
|
||||||
# print(hour)
|
# print(hour)
|
||||||
if hour >= 0 and hour < 12:
|
if hour >= 0 and hour < 12:
|
||||||
speak("Good Morning" + MASTER)
|
speak("Good Morning" + MASTER)
|
||||||
|
|
||||||
elif hour >= 12 and hour < 18:
|
elif hour >= 12 and hour < 18:
|
||||||
speak("Good Afternoon" + MASTER)
|
speak("Good Afternoon" + MASTER)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
speak("Good Evening" + MASTER)
|
speak("Good Evening" + MASTER)
|
||||||
|
|
||||||
# speak("Hey I am Jarvis. How may I help you")
|
|
||||||
|
|
||||||
|
# speak("Hey I am Jarvis. How may I help you")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
MASTER = config['DEFAULT']['MASTER']
|
MASTER = config['DEFAULT']['MASTER']
|
||||||
@ -99,29 +86,29 @@ def main():
|
|||||||
def takeCommand():
|
def takeCommand():
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
print("Listening....")
|
if debug == "True":print("Listening....")
|
||||||
|
else:pass
|
||||||
r.pause_threshold = 0.5
|
r.pause_threshold = 0.5
|
||||||
audio = r.listen(source)
|
audio = r.listen(source)
|
||||||
|
|
||||||
query = " "
|
query = " "
|
||||||
try:
|
try:
|
||||||
print("Recognizing....")
|
if debug == "True":print("Recognizing....")
|
||||||
|
else:pass
|
||||||
query = r.recognize_google(audio, language="en-in")
|
query = r.recognize_google(audio, language="en-in")
|
||||||
print("user said: " + query)
|
if debug == "True":print("user said: " + query)
|
||||||
|
else:pass
|
||||||
|
|
||||||
except sr.UnknownValueError:
|
except sr.UnknownValueError:
|
||||||
if debug == "True":
|
if debug == "True":print("Sorry Could You please try again")
|
||||||
print("Sorry Could You please try again")
|
else:pass
|
||||||
else:
|
|
||||||
pass
|
|
||||||
speak("Sorry Could You please try again")
|
speak("Sorry Could You please try again")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if debug == "True":
|
if debug == "True":
|
||||||
print(e)
|
print(e)
|
||||||
print("Say That Again Please")
|
print("Say That Again Please")
|
||||||
else:
|
else:pass
|
||||||
pass
|
|
||||||
query = None
|
query = None
|
||||||
|
|
||||||
return query
|
return query
|
||||||
@ -136,10 +123,8 @@ def main():
|
|||||||
speak("Searching wikipedia....")
|
speak("Searching wikipedia....")
|
||||||
query = query.replace("wikipedia", "")
|
query = query.replace("wikipedia", "")
|
||||||
results = wikipedia.summary(query, sentences=2)
|
results = wikipedia.summary(query, sentences=2)
|
||||||
if debug == "True":
|
if debug == "True":print(results)
|
||||||
print(results)
|
else:pass
|
||||||
else:
|
|
||||||
pass
|
|
||||||
speak(results)
|
speak(results)
|
||||||
|
|
||||||
elif "what's up" in query or "how are you" in query:
|
elif "what's up" in query or "how are you" in query:
|
||||||
@ -156,17 +141,16 @@ def main():
|
|||||||
try:
|
try:
|
||||||
open_url(popular_websites[website])
|
open_url(popular_websites[website])
|
||||||
except KeyError: # If the website is unknown
|
except KeyError: # If the website is unknown
|
||||||
if debug == "True":
|
if debug == "True":print(f"Unknown website: {website}")
|
||||||
print(f"Unknown website: {website}")
|
else:pass
|
||||||
else:
|
|
||||||
pass
|
|
||||||
speak(f"Sorry, i don't know the website {website}")
|
speak(f"Sorry, i don't know the website {website}")
|
||||||
speak(f"¿Do you want me to search {website} in the web?")
|
speak(f"¿Do you want me to search {website} in the web?")
|
||||||
if takeCommand() == "yes":
|
if takeCommand() == "yes":
|
||||||
search(website, search_engine)
|
search(website, search_engine )
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
elif "search" in query.lower():
|
elif "search" in query.lower():
|
||||||
search_query = query.split("for")[-1]
|
search_query = query.split("for")[-1]
|
||||||
search(search_query, search_engine)
|
search(search_query, search_engine)
|
||||||
@ -180,17 +164,15 @@ def main():
|
|||||||
speak("What should I say? ")
|
speak("What should I say? ")
|
||||||
content = takeCommand()
|
content = takeCommand()
|
||||||
|
|
||||||
email = config['EMAIL']
|
server = smtplib.SMTP(config['EMAIL']['server'], config['EMAIL']['port'])
|
||||||
server = smtplib.SMTP(email['server'], email['port'])
|
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.starttls()
|
server.starttls()
|
||||||
server.login(email['username'], email['password'])
|
server.login(config['EMAIL']['username'], config['EMAIL']['password'])
|
||||||
server.sendmail(email['username'], recipient, content)
|
server.sendmail(config['EMAIL']['username'], recipient, content)
|
||||||
server.close()
|
server.close()
|
||||||
speak("Email sent!")
|
speak("Email sent!")
|
||||||
except Exception:
|
except Exception:
|
||||||
speak("Sorry Sir!")
|
speak("Sorry Sir! I am unable to send your message at this moment!")
|
||||||
speak("I am unable to send your message at this moment!")
|
|
||||||
|
|
||||||
elif "nothing" in query or "abort" in query or "stop" in query:
|
elif "nothing" in query or "abort" in query or "stop" in query:
|
||||||
speak("okay")
|
speak("okay")
|
||||||
@ -215,6 +197,7 @@ def main():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
speak(e)
|
speak(e)
|
||||||
|
|
||||||
|
|
||||||
elif "pause music" in query:
|
elif "pause music" in query:
|
||||||
mixer.music.pause()
|
mixer.music.pause()
|
||||||
|
|
||||||
@ -226,12 +209,9 @@ def main():
|
|||||||
|
|
||||||
speak("Next Command! Sir!")
|
speak("Next Command! Sir!")
|
||||||
|
|
||||||
|
if os.path.isfile('./config.ini'): #Checks if config.ini exists.
|
||||||
if os.path.isfile('./config.ini'): # Checks if config.ini exists.
|
config = configparser.ConfigParser() #if exists loads library.
|
||||||
config = configparser.ConfigParser() # if exists loads library.
|
config.read('config.ini') #and also the file.
|
||||||
config.read('config.ini') # and also the file.
|
main() #Then launches the main program
|
||||||
main() # Then launchs the main program
|
|
||||||
else:
|
else:
|
||||||
# if it doesn't exist it drops an error message and exits.
|
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.
|
||||||
print('You need a config.ini file.')
|
|
||||||
print('Check the documentation in the Github Repository.')
|
|
||||||
|
|||||||
80
run.md
Normal file
80
run.md
Normal 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
|
||||||
|
```
|
||||||
Loading…
x
Reference in New Issue
Block a user