Merge pull request #36 from cclauss/pep8-naming
Date, time, and pep8-naming
This commit is contained in:
commit
457dfa386e
4
.github/workflows/lint_python.yml
vendored
4
.github/workflows/lint_python.yml
vendored
@ -7,8 +7,8 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v2
|
||||||
- run: pip install --upgrade pip wheel
|
- run: pip install --upgrade pip wheel
|
||||||
- run: pip install bandit black codespell flake8 flake8-bugbear
|
- run: pip install bandit black codespell flake8 flake8-bugbear flake8-comprehensions
|
||||||
flake8-comprehensions isort mypy pytest pyupgrade safety
|
flake8-return isort mypy pep8-naming 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 --ignore-words-list=ans
|
- run: codespell --ignore-words-list=ans
|
||||||
|
|||||||
60
Jarvis2.py
Normal file → Executable file
60
Jarvis2.py
Normal file → Executable file
@ -1,4 +1,7 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import getpass
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import smtplib
|
import smtplib
|
||||||
@ -10,12 +13,12 @@ import speech_recognition as sr
|
|||||||
import wikipedia
|
import wikipedia
|
||||||
|
|
||||||
print("Initializing Jarvis....")
|
print("Initializing Jarvis....")
|
||||||
MASTER = "Harsha"
|
MASTER = getpass.getuser()
|
||||||
|
|
||||||
|
|
||||||
engine = pyttsx3.init("nsss")
|
engine = pyttsx3.init("nsss")
|
||||||
voices = engine.getProperty("voices")
|
voices = engine.getProperty("voices")
|
||||||
engine.setProperty("voice", voices[0].id)
|
engine.setProperty("voice", voices[0].id)
|
||||||
|
|
||||||
popular_websites = {
|
popular_websites = {
|
||||||
"google": "https://www.google.com",
|
"google": "https://www.google.com",
|
||||||
"youtube": "https://www.youtube.com",
|
"youtube": "https://www.youtube.com",
|
||||||
@ -47,15 +50,17 @@ def speak(text):
|
|||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
|
|
||||||
|
|
||||||
def wishMe():
|
def print_and_speak(text):
|
||||||
|
print(text)
|
||||||
|
speak(text)
|
||||||
|
|
||||||
|
|
||||||
|
def wish_me():
|
||||||
hour = datetime.datetime.now().hour
|
hour = datetime.datetime.now().hour
|
||||||
# print(hour)
|
if hour < 12:
|
||||||
if hour >= 0 and hour < 12:
|
|
||||||
speak("Good Morning" + MASTER)
|
speak("Good Morning" + MASTER)
|
||||||
|
elif 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)
|
||||||
|
|
||||||
@ -65,50 +70,53 @@ def wishMe():
|
|||||||
# This is where our programme begins....
|
# This is where our programme begins....
|
||||||
|
|
||||||
|
|
||||||
def takeCommand():
|
def take_command():
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
print("Listening....")
|
print("Listening....")
|
||||||
r.pause_threshold = 0.5
|
r.pause_threshold = 0.5
|
||||||
audio = r.listen(source)
|
audio = r.listen(source)
|
||||||
|
|
||||||
query = " "
|
print("Recognizing....")
|
||||||
|
query = ""
|
||||||
try:
|
try:
|
||||||
print("Recognizing....")
|
|
||||||
query = r.recognize_google(audio, language="en-in")
|
query = r.recognize_google(audio, language="en-in")
|
||||||
print("user said: " + query)
|
print("User said: " + query)
|
||||||
|
|
||||||
except sr.UnknownValueError:
|
except sr.UnknownValueError:
|
||||||
print("Sorry Could You please try again")
|
print("Sorry could you please try again?")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
print("Say That Again Please")
|
print("Say that again, please?")
|
||||||
query = None
|
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
speak("Initializing Jarvis....")
|
speak("Initializing Jarvis....")
|
||||||
wishMe()
|
wish_me()
|
||||||
query = takeCommand()
|
query = take_command().lower()
|
||||||
|
|
||||||
# logic for executing basic tasks
|
# logic for executing basic tasks
|
||||||
if "wikipedia" in query.lower():
|
if "wikipedia" in query.lower():
|
||||||
speak("Searching wikipedia....")
|
speak("Searching wikipedia....")
|
||||||
query = query.replace("wikipedia", "")
|
query = query.replace("wikipedia", "")
|
||||||
results = wikipedia.summary(query, sentences=2)
|
print_and_speak(wikipedia.summary(query, sentences=2))
|
||||||
print(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:
|
||||||
stMsgs = [
|
st_msgs = (
|
||||||
"Just doing my thing!",
|
"Just doing my thing!",
|
||||||
"I am fine!",
|
"I am fine!",
|
||||||
"Nice!",
|
"Nice!",
|
||||||
"I am nice and full of energy",
|
"I am nice and full of energy",
|
||||||
]
|
)
|
||||||
speak(random.choice(stMsgs))
|
speak(random.choice(st_msgs))
|
||||||
|
|
||||||
|
elif "date" in query:
|
||||||
|
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
||||||
|
|
||||||
|
elif "time" in query:
|
||||||
|
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
||||||
|
|
||||||
elif "open" in query.lower():
|
elif "open" in query.lower():
|
||||||
website = query.replace("open", "").strip().lower()
|
website = query.replace("open", "").strip().lower()
|
||||||
@ -116,7 +124,7 @@ elif "open" in query.lower():
|
|||||||
open_url(popular_websites[website])
|
open_url(popular_websites[website])
|
||||||
except IndexError: # If the website is unknown
|
except IndexError: # If the website is unknown
|
||||||
print(f"Unknown website: {website}")
|
print(f"Unknown website: {website}")
|
||||||
speak(f"Sorry, i don't know the website {website}")
|
speak(f"Sorry, I don't know the website {website}")
|
||||||
|
|
||||||
elif "search" in query.lower():
|
elif "search" in query.lower():
|
||||||
search_query = query.split("for")[-1]
|
search_query = query.split("for")[-1]
|
||||||
@ -125,12 +133,12 @@ elif "search" in query.lower():
|
|||||||
|
|
||||||
elif "email" in query:
|
elif "email" in query:
|
||||||
speak("Who is the recipient? ")
|
speak("Who is the recipient? ")
|
||||||
recipient = takeCommand()
|
recipient = take_command()
|
||||||
|
|
||||||
if "me" in recipient:
|
if "me" in recipient:
|
||||||
try:
|
try:
|
||||||
speak("What should I say? ")
|
speak("What should I say? ")
|
||||||
content = takeCommand()
|
content = take_command()
|
||||||
|
|
||||||
server = smtplib.SMTP("smtp.gmail.com", 587)
|
server = smtplib.SMTP("smtp.gmail.com", 587)
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
|
|||||||
@ -49,7 +49,7 @@ def speak(text):
|
|||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
|
|
||||||
|
|
||||||
def wishMe():
|
def wish_me():
|
||||||
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:
|
||||||
@ -65,14 +65,14 @@ def wishMe():
|
|||||||
|
|
||||||
|
|
||||||
# This is where our programme begins....
|
# This is where our programme begins....
|
||||||
def takeCommand():
|
def take_command():
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
print("Listening....")
|
print("Listening....")
|
||||||
r.pause_threshold = 0.5
|
r.pause_threshold = 0.5
|
||||||
audio = r.listen(source)
|
audio = r.listen(source)
|
||||||
|
|
||||||
query = " "
|
query = ""
|
||||||
try:
|
try:
|
||||||
print("Recognizing....")
|
print("Recognizing....")
|
||||||
query = r.recognize_google(audio, language="en-in")
|
query = r.recognize_google(audio, language="en-in")
|
||||||
@ -84,15 +84,14 @@ def takeCommand():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
print("Say That Again Please")
|
print("Say That Again Please")
|
||||||
query = None
|
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
speak("Initializing Jarvis....")
|
speak("Initializing Jarvis....")
|
||||||
wishMe()
|
wish_me()
|
||||||
while True:
|
while True:
|
||||||
query = takeCommand()
|
query = take_command()
|
||||||
|
|
||||||
# logic for executing basic tasks
|
# logic for executing basic tasks
|
||||||
if "wikipedia" in query.lower():
|
if "wikipedia" in query.lower():
|
||||||
@ -103,13 +102,13 @@ while True:
|
|||||||
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:
|
||||||
stMsgs = [
|
st_msgs = [
|
||||||
"Just doing my thing!",
|
"Just doing my thing!",
|
||||||
"I am fine!",
|
"I am fine!",
|
||||||
"Nice!",
|
"Nice!",
|
||||||
"I am nice and full of energy",
|
"I am nice and full of energy",
|
||||||
]
|
]
|
||||||
speak(random.choice(stMsgs))
|
speak(random.choice(st_msgs))
|
||||||
|
|
||||||
elif "open" in query.lower():
|
elif "open" in query.lower():
|
||||||
website = query.replace("open", "").strip().lower()
|
website = query.replace("open", "").strip().lower()
|
||||||
@ -126,12 +125,12 @@ while True:
|
|||||||
|
|
||||||
elif "mail" in query:
|
elif "mail" in query:
|
||||||
speak("Who is the recipient? ")
|
speak("Who is the recipient? ")
|
||||||
recipient = takeCommand()
|
recipient = take_command()
|
||||||
|
|
||||||
if "me" in recipient:
|
if "me" in recipient:
|
||||||
try:
|
try:
|
||||||
speak("What should I say? ")
|
speak("What should I say? ")
|
||||||
content = takeCommand()
|
content = take_command()
|
||||||
|
|
||||||
server = smtplib.SMTP("smtp.gmail.com", 587)
|
server = smtplib.SMTP("smtp.gmail.com", 587)
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user