Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JARVIS

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

import time

import pyautogui
import pyttsx3
import pywhatkit
import requests
import speech_recognition as sr
import datetime
import os
from requests import get
import wikipedia
import webbrowser
import pywhatkit as kit
import sys
import pyjokes
import smtplib

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
engine.setProperty('voices' , voices[0].id)

#text to speech
def speak(audio):
engine.say(audio)
engine.runAndWait()
print(audio)

#To convert voice into text


def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('listening...')
r.pause_threshold = 1
audio = r.listen(source, timeout=1, phrase_time_limit=5)

try:
print('Recognizing...')
query = r.recognize_google(audio, language= 'en-in')
print(f"user said: {query}")

except Exception as e:
speak('Say that again please...')
return "none"
return query

#to wish
def wish():
hour = int(datetime.datetime.now().hour)

if hour>=0 and hour<=12:


speak('good morning')

elif hour>=12 and hour<=18:


speak('good evening')
else:
speak('good afternoon')
speak('I am JARVIS sir. Please tell me how may i help you')

#to send mail


def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 535)
server.ehlo()
server.starttls()
server.login('amalikamaliktp@gmail.com', 'Am197580')
server.sendmail('amalikamaliktp@gmail.com', to, content)
server.close()

#for fetching news


def news():
main_url = 'http://819887499bc84d23bb01006b6f512f64?'
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[articles])
for i in range(len(day)):
speak(f'todays {day[i]} news is {head[i]}')

if __name__ == '__main__':
wish()
while True:

query = takecommand().lower()

#logic building for tasks

if "open notepad" in query:


npath = 'C:\\Windows\\system32\\notepad.exe'
os.startfile(npath)

elif "open reader" in query:


arpath = 'C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\
AcroRd32.exe'
os.startfile(arpath)

elif "open command prompt" in query:


os.system('start cmd')

elif "open maths book pdf" in query:


mpath= 'https:\\www.learncbse.in\\ncert-class-7-maths-book-pdf-free-
download\\'
os.startfile(mpath)

elif "ip address" in query:


ip = get('https://api.ipify.org').text
speak(f'your ip address is {ip}')

elif "wikipedia" in query:


speak('searching wikipedia...')
query = query.replace('wikipedia', '')
results = wikipedia.summary(query, sentences=2)
speak('according to wikipedia')
print(results)
speak(results)

elif "search google" in query:


speak('what should i search on google sir...')
cm = takecommand().lower()
webbrowser.open(f'{cm}')

elif "send whatsapp message" in query:


speak('what should i say in the message sir...')
msg = takecommand().lower()
speak('to whom should i send the message sir')
phone = takecommand().lower()
kit.sendwhatmsg(f'{phone}',f'{msg}',)
speak('the message has been sent')

elif "play youtube" in query:


speak('what should i play on youtube sir...')
mc = takecommand().lower()
pywhatkit.playonyt(f'{mc}')

elif "power off" in query:


speak('thank you sir.. TAKE CARE')
sys.exit()

elif "send mail to ramachandran" in query:


try:
speak('what should i say in the mail...')
content = takecommand().lower()
to = 'ramachandranaadhidev2008@gmail.com'
sendEmail(to, content)
speak('Email has been send to Aadhi...')

except Exception as e:
print(e)
speak('Sorry sir, coudnt send the mail, if it is an important
message, why not try sending using whatsapp')

elif "no need thank you" in query:


speak('ok sir, is there anything else i can help u with??')

elif "make me laugh" in query:


joke = pyjokes.get_joke()
speak(joke)

elif "switch the window" in query:


pyautogui.keyDown("alt")
pyautogui.press("tab")
time.sleep(1)
pyautogui.keyUp("alt")
elif "news" in query:
speak('please wait sir...Fetching the latest news ')
news()

elif "where am i" in query:


speak('please wait sir, tracking GPS....')
try:
ipAdd = requests.get('https://api.ipify.org').text
print(ipAdd)
url = 'https://get.geojs.io/v1/ip/geo/'+ipAdd+'.json'
geo_requests = requests.get(url)
geo_data = geo_requests.json()
city = geo_data['city']
country = geo_data['country']
speak(f'according to GPS, we are at {city},{country}')

except Exception as e:
speak('sorry sir, i am not able to trach GPS for the moment, is
there anything else i can help u with...')

elif "discord server" in query:


try:
name = input('please enter username here:')
webbrowser.open(f'www.discord.com/{name}')
speak(f'here is the server of the user {name}')
time.sleep(10)

except Exception as e:
print(e)
speak('sorry sir, i could not open the server')

elif "capture the screen" in query:


speak('sir, please tell the name for this screenshot')
name = takecommand().lower()
speak('sir, please hold the screen for a few seconds, i m capturing the
screen..')
time.sleep(3)
img = pyautogui.screenshot()
img.save(f'{name}.png')
speak('Done sir. i have captured your screen, it is saved to our
folder, please go and check it')
#to close any application
elif "close notepad" in query:
speak('ok sir. closing notepad...')
os.system('taskkill /f /im notepad.exe')

elif "close reader" in query:


speak('ok sir. closing abobe reader...')
os.system('taskkill /f /im AcroRd32.exe')

elif "close command prompt" in query:


os.system('taskkill /f /im cmd.exe')

You might also like