From 80e06a87cf13af2e8d6ed6bbb61f816779c79563 Mon Sep 17 00:00:00 2001 From: Krish Gupta Date: Wed, 6 Oct 2021 08:01:47 +0530 Subject: [PATCH 1/2] docs: coc --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..103844f --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[@Harsha200105](https://github.com/Harsha200105). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From cfbefeb8814cbf08030ec92e72ab5e3bc58bcbff Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 6 Oct 2021 08:14:43 +0200 Subject: [PATCH 2/2] GitHub Action to lint Python code Test results: https://github.com/cclauss/DesktopAssitant/actions --- .github/workflows/lint_python.yml | 23 ++++++ Jarvis2.py | 123 +++++++++++++++-------------- Jarvis2_4windows.py | 127 ++++++++++++++++-------------- 3 files changed, 157 insertions(+), 116 deletions(-) create mode 100644 .github/workflows/lint_python.yml diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 0000000..c3b9dc0 --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,23 @@ +name: lint_python +on: [pull_request, push] +jobs: + lint_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install --upgrade pip wheel + - run: pip install bandit black codespell flake8 flake8-bugbear + flake8-comprehensions isort mypy pytest pyupgrade safety + - run: bandit --recursive --skip B311,B605 . + - run: black --check . || true + - run: codespell + - 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 + - run: mkdir --parents --verbose .mypy_cache + - run: mypy --ignore-missing-imports --install-types --non-interactive . + - run: pytest . || true + - run: pytest --doctest-modules . || true + - run: shopt -s globstar && pyupgrade --py36-plus **/*.py + - run: safety check diff --git a/Jarvis2.py b/Jarvis2.py index dcd3bed..e2710c8 100644 --- a/Jarvis2.py +++ b/Jarvis2.py @@ -1,39 +1,45 @@ -import pyttsx3 -import speech_recognition as sr import datetime -import wikipedia -import webbrowser import os +import random import smtplib import sys -import random +import webbrowser + +import pyttsx3 +import speech_recognition as sr +import wikipedia print("Initializing Jarvis....") MASTER = "Harsha" -engine = pyttsx3.init('nsss') -voices = engine.getProperty('voices') -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'} +engine = pyttsx3.init("nsss") +voices = engine.getProperty("voices") +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' + chrome_path = r"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}') + open_url(f"{search_engines[search_engine]}/search?q={search_query}") except IndexError: - open_url(f'https://www.google.com/search?q={search_query}') + open_url(f"https://www.google.com/search?q={search_query}") def speak(text): @@ -58,6 +64,7 @@ def wishMe(): # This is where our programme begins.... + def takeCommand(): r = sr.Recognizer() with sr.Microphone() as source: @@ -68,7 +75,7 @@ def takeCommand(): query = " " try: print("Recognizing....") - query = r.recognize_google(audio, language='en-in') + query = r.recognize_google(audio, language="en-in") print("user said: " + query) except sr.UnknownValueError: @@ -87,70 +94,72 @@ wishMe() query = takeCommand() # logic for executing basic tasks -if 'wikipedia' in query.lower(): - speak('Searching wikipedia....') +if "wikipedia" in query.lower(): + speak("Searching wikipedia....") query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) print(results) speak(results) -elif "what\'s up" in query or 'how are you' in query: - stMsgs = ['Just doing my thing!', 'I am fine!', - 'Nice!', 'I am nice and full of energy'] +elif "what's up" in query or "how are you" in query: + stMsgs = [ + "Just doing my thing!", + "I am fine!", + "Nice!", + "I am nice and full of energy", + ] speak(random.choice(stMsgs)) -elif 'open' in query.lower(): - website = query.replace('open', '').strip().lower() +elif "open" 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}') + 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(): - search_query = query.split('for')[-1] - search_engine = query.split('for')[0].replace('search', '').strip().lower() +elif "search" in query.lower(): + search_query = query.split("for")[-1] + search_engine = query.split("for")[0].replace("search", "").strip().lower() search(search_query, search_engine) - -elif 'email' in query: - speak('Who is the recipient? ') +elif "email" in query: + speak("Who is the recipient? ") recipient = takeCommand() - if 'me' in recipient: + if "me" in recipient: try: - speak('What should I say? ') + speak("What should I say? ") content = takeCommand() - server = smtplib.SMTP('smtp.gmail.com', 587) + server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo() server.starttls() - server.login("Your_Username", 'Your_Password') - server.sendmail('Your_Username', "Recipient_Username", content) + server.login("Your_Username", "Your_Password") + server.sendmail("Your_Username", "Recipient_Username", content) server.close() - speak('Email sent!') + speak("Email sent!") + except Exception: + speak("Sorry Sir! I am unable to send your message at this moment!") - except: - 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') - speak('Bye Sir, have a good day.') +elif "nothing" in query or "abort" in query or "stop" in query: + speak("okay") + speak("Bye Sir, have a good day.") sys.exit() -elif 'hello' in query: - speak('Hello Sir') +elif "hello" in query: + speak("Hello Sir") -elif 'bye' in query: - speak('Bye Sir, have a good day.') +elif "bye" in query: + speak("Bye Sir, have a good day.") sys.exit() -elif 'play music' in query: - music_folder = 'Your_music_folder_path(absolute_path)' - music = ['music1', 'music2', 'music3', 'music4','music5'] - random_music = music_folder + random.choice(music) + '.mp3' +elif "play music" in query: + music_folder = "Your_music_folder_path(absolute_path)" + music = ("music1", "music2", "music3", "music4", "music5") + random_music = music_folder + random.choice(music) + ".mp3" os.system(random_music) - speak('Playing your request') + speak("Playing your request") -speak('Next Command! Sir!') +speak("Next Command! Sir!") diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 2435c33..bb9aa14 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -1,40 +1,46 @@ -import pyttsx3 -import speech_recognition as sr import datetime -import wikipedia -import webbrowser -import os +import random import smtplib import sys -import random +import webbrowser + +import pyttsx3 +import speech_recognition as sr +import wikipedia from pygame import mixer + mixer.init() print("Initializing Jarvis....") MASTER = "Tony Stark" -engine = pyttsx3.init('sapi5') # -voices = engine.getProperty('voices') -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'} +engine = pyttsx3.init("sapi5") +voices = engine.getProperty("voices") +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' + chrome_path = r"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}') + open_url(f"{search_engines[search_engine]}/search?q={search_query}") except IndexError: - open_url(f'https://www.google.com/search?q={search_query}') + open_url(f"https://www.google.com/search?q={search_query}") def speak(text): @@ -68,7 +74,7 @@ def takeCommand(): query = " " try: print("Recognizing....") - query = r.recognize_google(audio, language='en-in') + query = r.recognize_google(audio, language="en-in") print("user said: " + query) except sr.UnknownValueError: @@ -88,78 +94,81 @@ while True: query = takeCommand() # logic for executing basic tasks - if 'wikipedia' in query.lower(): - speak('Searching wikipedia....') + if "wikipedia" in query.lower(): + speak("Searching wikipedia....") query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) print(results) speak(results) - elif "what\'s up" in query or 'how are you' in query: - stMsgs = ['Just doing my thing!', 'I am fine!', - 'Nice!', 'I am nice and full of energy'] + elif "what's up" in query or "how are you" in query: + stMsgs = [ + "Just doing my thing!", + "I am fine!", + "Nice!", + "I am nice and full of energy", + ] speak(random.choice(stMsgs)) - elif 'open' in query.lower(): - website = query.replace('open', '').strip().lower() + elif "open" 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}') + 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(): - search_query = query.split('for')[-1] - search_engine = query.split('for')[0].replace('search', '').strip().lower() + elif "search" in query.lower(): + search_query = query.split("for")[-1] + search_engine = query.split("for")[0].replace("search", "").strip().lower() search(search_query, search_engine) - elif 'mail' in query: - speak('Who is the recipient? ') + elif "mail" in query: + speak("Who is the recipient? ") recipient = takeCommand() - if 'me' in recipient: + if "me" in recipient: try: - speak('What should I say? ') + speak("What should I say? ") content = takeCommand() - server = smtplib.SMTP('smtp.gmail.com', 587) + server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo() server.starttls() - server.login("Your_Username", 'Your_Password') - server.sendmail('Your_Username', "Recipient_Username", content) + server.login("Your_Username", "Your_Password") + server.sendmail("Your_Username", "Recipient_Username", content) server.close() - speak('Email sent!') + speak("Email sent!") + except Exception: + speak("Sorry Sir! I am unable to send your message at this moment!") - except: - 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') - speak('Bye Sir, have a good day.') + elif "nothing" in query or "abort" in query or "stop" in query: + speak("okay") + speak("Bye Sir, have a good day.") sys.exit() - elif 'hello' in query: - speak('Hello Sir') + elif "hello" in query: + speak("Hello Sir") - elif 'bye' in query: - speak('Bye Sir, have a good day.') + elif "bye" in query: + speak("Bye Sir, have a good day.") sys.exit() - elif 'play music' in query: + elif "play music" in query: music_folder = "Your_music_folder_path(absolute_path)" - music = ['music1', 'music2', 'music3', 'music4'] - random_music = music_folder + random.choice(music) + '.mp3' - speak('Playing your request') + music = ("music1", "music2", "music3", "music4") + random_music = music_folder + random.choice(music) + ".mp3" + speak("Playing your request") mixer.music.load(random_music) mixer.music.play() - elif 'pause music' in query: + elif "pause music" in query: mixer.music.pause() - elif 'stop music' in query: + elif "stop music" in query: mixer.music.stop() - elif 'unpause' in query: + elif "unpause" in query: mixer.music.unpause() - speak('Next Command! Sir!') + speak("Next Command! Sir!")