And open it in your source code editor for e.g Vs code, pycharm .
The you have to install some module by typing pip install:-
1:os
2:smtplib
3:webbrowser
4pyttsx3
5:speech_recognition
6:wikipedia
7:requests
8:time
9:pyjokes
10:pyautogui
11:operator
12:bs4
13:pywikihow
This much and now copy this command and past it in your .py file
The command are here:-
import datetime
import os
import smtplib
import sys
import webbrowser
import pyttsx3
import speech_recognition as sr
import wikipedia
from requests import get
import requests
import time
import pyjokes
import pyautogui
import requests
import operator
from bs4 import BeautifulSoup
from wikipedia.wikipedia import search
from pywikihow import search_wikihow
import pywikihow
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
#print(voice)
engine.setProperty('voice',voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
tt = time.strftime("%I:%M %p")
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
print(f"Good Morning sir it's {tt} and in itahari it is")
speak(f"Good Morning sir it's {tt},and in itahari it is,")
search = "temperature in itahari"
url =f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
temp = data.find("div",class_="BNeawe").text
print(f"{temp}")
speak(f"{temp}")
elif hour>=12 and hour<18:
print(f"Good Afternoon sir it's {tt} and in itahari it is")
speak(f"Good Afternoon sir it's {tt},and in itahari it is,")
search = "temperature in itahari"
url =f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
temp = data.find("div",class_="BNeawe").text
print(f"{temp}")
speak(f"{temp}")
else:
print(f"Good Evening sir it's {tt}and in itahari it is")
speak(f"Good Evening sir it's {tt},and in itahari it is,")
search = "temperature in itahari"
url =f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
temp = data.find("div",class_="BNeawe").text
print(f"{temp}")
speak(f"{temp}")
print(f"I am jarvis sir. How may i help you sir")
speak(f"I am jarvis sir. How may i help you sir")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening sir...")
r.pause_threshold = 1
audio = r.listen(source,timeout=4,phrase_time_limit=7)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n" )
except Exception as e:
print("say again please...")
return "None"
query = query.lower()
return query
def news():
main_url = 'https://newsapi.org/v2/top-headlines?sources-techcrunch&apikey=a72e0b429a10414d9109f0dcae25a165'
main_page =requests.get(main_url).json()
articles = main_page["articles"]
head = []
day=['first','second','third','fourth','fifth','sixth','seventh','eighth','ninth','tenth']
for ar in articles:
head.append(ar["title"])
for i in range (len(day)):
speak(f"today's {day[i]}news is: {head[i]}")
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('arisze13@gmail.com', 'mission56789!')
server.sendmail('arisze13@gmail.com', to, content)
server.quit()
def task():
wishMe()
while True:
query = takeCommand().lower()
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace('wikipedia', "")
result = wikipedia.summary(query, sentences=5)
speak("Acording to wikipedia")
print(result)
speak(result)
elif 'open youtube' in query:
speak("what should i search")
ask2 = takeCommand().lower()
webbrowser.open(f"www.youtube.com/results?search_query={ask2}")
elif 'open google' in query:
speak("what should i search in google?")
ask = takeCommand().lower()
webbrowser.open(f"www.google.com/search?q={ask}")
elif 'open stack overflow' in query:
webbrowser.open("www.stackoverflow.com")
elif 'download music' in query:
webbrowser.open("www.loudtronix.com")
elif 'play xxxtentacion song' in query:
music_dir = 'D:\song'
songs = os.listdir(music_dir)
os.startfile(os.path.join(music_dir, songs[0]))
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")
elif "open code" in query:
codePath = "C:\\Users\\masova\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
elif "email to mum" in query:
speak("what should I send to mom?")
content = takeCommand()
to = "karkishova92@gmail.com"
sendEmail(to, content)
speak("email has been send")
elif "thanks" in query:
speak("You are welcome my friend")
elif "you are the best" in query:
speak("thank you my friend")
elif "open command" in query:
speak("opening command prompt")
os.system("start cmd")
elif "open notepad" in query:
speak("opening notepad")
os.system("start notepad")
elif "close notepad" in query:
speak("closing notepad ")
os.system("taskkill /f /im notepad.exe")
elif "ip address" in query:
ip = get('https://api.ipify.org').text
print(ip)
speak(f"your ip address is{ip}")
elif "open facebook" in query:
webbrowser.open("https://www.facebook.com")
speak("may I open messenger if yes tell me, open messenger")
elif "open messenger" in query:
webbrowser.open("https://messenger.com")
elif "alarm" in query:
speak('setting alarm')
nn = int(datetime.datetime.now().hour)
if nn==22:
music_dir = 'D:\song'
song = os.listdir(music_dir)
os.startfile(os.path.join(music_dir, song[0]))
elif "joke" in query:
joke = pyjokes.get_joke(language='en')
print(joke)
speak(joke)
elif "shutdown" in query:
os.system("shutdown /s /t 5")
elif "restart" in query:
os.system("shutdown /r /t 5")
elif "sleep my pc" in query:
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
elif "news" in query:
speak("please wait searching for the latest news")
ns = news()
print(ns)
speak(f"todays latest is {ns} ")
elif "switch the window" in query:
pyautogui.keyDown('alt')
pyautogui.press('tab')
time.sleep(1)
pyautogui.keyUp('alt')
elif "where i am" in query or "where we are" in query:
speak("wait sir, let me check")
ipAdd = requests.get('https://get.geojs.io/').test
print(ipAdd)
url = 'https://get.geojs.io/v1/ip/geo/'+ipAdd+'.js'
geo_requests = requests.get(url)
geo_data = geo_requests.json()
city = geo_data['city']
country = geo_data['country']
speak(f'sir i am not sure, but i think we are in {city} city of {country} country')
elif "calculate" in query:
try:
r = sr.Recognizer()
with sr.Microphone() as source:
speak('Sir, what you want to calculate')
print('listening...')
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
my_string = r.recognize_google(audio)
print(my_string)
def get_operator_fn(op):
return {
'+' : operator.add,
'-' : operator.sub,
'x' :operator.mul,
'divided' :operator.__truediv__,
}[op]
def eval_binary_expr(op1, oper, op2):
op1,op2 = int(op1), int(op2)
return get_operator_fn(oper)(op1, op2)
speak("your result is")
print("your result is",eval_binary_expr(*(my_string.split())))
speak(eval_binary_expr(*(my_string.split())))
except Exception as e:
print('sorry sir, I cannot calculate because of some problem to solve this problem you have to give two number not one number')
speak('sorry sir, I cannot calculate because of some problem to solve this problem you have to give two number not one number')
elif 'hello' in query:
print('Hello sir, how may I help you sir?')
speak('Hello sir, how may I help you sir?')
elif 'how are you' in query:
print("I am fine sir, what about you?")
speak('I am fine sir, what about you?')
elif 'i am fine' in query:
print('That''s''great')
speak('That''s''great')
elif 'who are you' in query:
print('I am jarvis sir, made by mission')
speak('I am jarvis sir, made by mission')
elif "you can sleep now" in query:
print("bye bye, my friend you can call me any time")
speak("bye bye, my friend you can call me any time")
break
elif "temperature" in query:
search = "temperature in itahari"
url =f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
temp = data.find("div",class_="BNeawe").text
print(f"current {search} is {temp}")
speak(f"current {search} is {temp}")
elif "activate how to do mode" in query:
speak("How to do mode is activated please tell me what you want to know?")
how = takeCommand()
max_results = 5
how_to = search_wikihow(how, max_results)
assert len(how_to) == 5
how_to[0]-print()
speak(how_to[0].summary)
elif 'play music' in query:
try:
print("which song you want to play?")
speak("which song you want to play?")
op = takeCommand()
webbrowser.open(f"https://{op}.mp3quack.lol/")
except Exception as e:
speak("i can't play music right now you can fix it by checking you wifi ")
if __name__ == "__main__":
per = takeCommand()
if "wake up" in per:
task()
elif "good bye" in per:
print("Bye bye sir, see you later, have a good day")
speak("Bye bye sir, see you later, have a good day")
