So This can be your first mega python project. This can be used to astonish your friends and impress your professors. I tried to keep the code simple so beginners can understand this too.
This code is probably the best among the others as it has got lots of functionality.
Surprisingly you can schedule your WhatsApp messages without even using your keyboard this is one of the cool features. If you liked the project give thumbs up and comment down below other project suggestions until then stay safe and enjoy.
First Install following Modules :
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import pyautogui
import smtplib
import pywhatkit
import psutil
from bs4 import BeautifulSoup
import requests
from urllib.request import urlopen
import wolframalpha
import json
import time
import googletrans
import ctypes
#code with mahattva
# ===============================================================>
# --------------------------------------------------------------------
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
# --------------------------------------------------------------------
def speak(audio):
engine.say(audio)
engine.runAndWait()
# ------------------------------------------------------------------------
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak(" A very Good Morning sir")
elif hour>=12 and hour<18:
speak(" A veryGood Afternoon sir")
else:
speak(" A very Good Evening sir ")
speak(" How are you doing ...... by the way you are looking handsome as always ")
# ----------------------------------------------------------------------------
#code with mahattva
# =========================engine===============================================
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-IN')
print(f"User said: {query}\n")
except Exception as e:
speak("Say that again please...")
return "None"
return query
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('mahattva.sahu@gmail.com', '26may2004')
server.sendmail('dhirendra.dhar@gmail.com', to, content)
server.close()
# -------------------------------------------------------------------------------
app = wolframalpha.Client("3579Y5-85E7A6AJ47")
if __name__ == "__main__":
wishMe()
while True:
# if 1:
query = takeCommand().lower()
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
# ====================================================================================>
# =================================== funtional operators =============================================
elif 'open youtube' in query:
webbrowser.open("youtube.com/physicswallah")
speak("opening youtube sir ")
elif 'open google' in query:
speak("what should i search on google sir")
cm = takeCommand()
webbrowser.open(f"{cm}")
speak("opening google sir")
elif 'find the average ' in query:
speak("Tell the first number")
a = takeCommand()
a =int(a)
speak("Tell the second number")
b = takeCommand()
b =int(b)
avg = (a+b)/2
print("average is ", avg)
elif 'open whatsapp' in query:
webbrowser.open("https://web.whatsapp.com/.com")
speak(" opening whatsapp sir")
elif 'open zoom' in query:
codePath = "C:\\Users\\Mahattva\\AppData\\Roaming\\Zoom\\bin\\Zoom.exe"
os.startfile(codePath)
speak(" opening the meeting")
elif 'play some music' in query:
music_dir = 'D:\\zara\\songs'
songs = os.listdir(music_dir)
speak("here is your favorite song")
os.startfile(os.path.join(music_dir, songs[1]))
exit()
elif 'show photos' in query:
codePath = "D:\\PD "
os.startfile(codePath)
speak("here are your photoes")
elif 'open code' in query:
codePath = "C:\\Users\\Mahattva\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
speak("opening your code editor")
elif 'send a whatsapp message' in query:
try:
speak("What should I say sir?")
content = takeCommand()
to =('+919981321049')
speak( "mention the hours please")
time_hour = int(takeCommand())
speak("mention the minutes")
time_min = int(takeCommand())
pywhatkit.sendwhatmsg(to, content,time_hour,time_min)
speak("message has been sent!")
except Exception as e:
print(e)
speak("Sorry sir . I am not able to send this message")
elif " how much battery left " in query or "how much power left" in query or "battery" in query:
battery = psutil.sensors_battery()
percentage = battery.percent
speak(f"sir the system is running on {percentage} percent of battery life")
if percentage>= 80:
speak("sir there is enough battery left")
elif percentage >= 50 and percentage<=79:
speak("sir the battery would sustain an hour long more")
elif percentage>=20 and percentage<=49:
speak(" sir the battery would sustain half an hour long more")
elif percentage<=19:
speak("sir the battery shall soon exhaust ....please power the device now")
elif 'the time' in query or "what's the time " in query or "tell me the time" in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")
elif 'volume up' in query or 'raise volume' in query :
pyautogui.press("volume up")
elif 'volume down ' in query or 'decrese volume' in query:
pyautogui.press("volume down")
elif 'mute' in query or 'mute volume' in query:
pyautogui.press("volumemute")
elif 'temperature' in query or 'how is the weather outside ' in query:
res = app.query(query)
abc = ((next(res.results).text))
speak(f"sir the temperature outside is {abc}......feels like you should go for a ride ")
elif "don't listen" in query or "stop listening" in query:
speak("sir for how much time ")
a = int(takeCommand())
time.sleep(a)
print(a)
elif 'lock' in query or 'lock the device' in query or 'lock window' in query:
speak("locking the device")
ctypes.windll.user32.LockWorkStation()
exit()
elif 'news' in query or 'update'in query or 'todays news' in query:
def NewsFromBBC():
query_params = {
"source": "bbc-news",
"sortBy": "top",
"apiKey": "4dbc17e007ab436fb66416009dfb59a8"
}
main_url = " https://newsapi.org/v1/articles"
# fetching data in json format
res = requests.get(main_url, params=query_params)
open_bbc_page = res.json()
# getting all articles in a string article
article = open_bbc_page["articles"]
# empty list which will
# contain all trending news
results = []
for ar in article:
results.append(ar["title"])
for i in range(len(results)):
# printing all trending news
print(i + 1, results[i])
#to read the news out loud for us
from win32com.client import Dispatch
speak = Dispatch("SAPI.Spvoice")
speak.Speak(results)
# Driver Code
if __name__ == '__main__':
# function call
NewsFromBBC()
# =================================================================================================
# ========================== dialouges=============================================
elif 'shut up' in query:
speak(" i am really sorry , I apologise for my mistake")
elif 'who am i' in query:
speak("you are simply a genius.....and the most intelligent creature in world ")
elif 'ok fine' in query:
speak("sir give next order please")
elif 'what is your religion' in query:
speak("i don't have any religion sir . my god is my creater")
elif 'wish me' in query or 'wish me jarvis ' in query :
speak("all the best for your exams sir........")
elif 'let me sleep' in query:
speak("sir ..... please wakeup or else we will miss the classes ")
elif 'tip tip barsa' in query or 'tip tip' in query or 'pani' in query:
speak("water..lit..the fire up")
elif 'jine mera dil luteya ' in query or 'jine ' in query or 'luteya' in query or 'जीने मेरा दिल लूटेया'in query:
speak("oO ho")
elif 'no please' in query:
speak("sir then please wake its already late ")
elif 'thank you' in query or 'thank you so much' in query:
speak(" Its my pleasure sir that i was usefull")
elif 'how are you jarvis'in query or 'how are you ' in query:
speak(" i am good sir how are you")
elif 'I am not feeling well today' in query or 'not feeling well' in query or 'feeling' in query:
speak("what happened sir every thing all right ..... shall i can out ambulance")
elif 'good morning' in query:
speak("A very good morning sir , hope you acheive every thing today , hustle hard ")
elif 'good afternoon' in query:
speak( " i am sure you are done with your lunch")
elif 'good evening' in query:
speak("how was your day sir hope you enjoyed it , are you done with you are daily tasks?")
elif 'open my physics class' in query:
webbrowser.open("youtube.com/physicswallah")
speak("opening your classes sir ")
elif 'nothing' in query or 'kuch nahi' in query:
speak(" ok sir waiting for your call ")
elif 'who created you' in query:
speak('i was made by my master .....and rest is secret')
elif 'why were you slow last time' in query:
speak("sorry sir ... i will take care from next time.... its my promise")
elif 'who is your creater' in query or 'who made you' in query:
speak(" sorry..... but i can't tell you that .......but belive me he is a real genius")
elif 'sun na ' in query or 'sunn yarr' in query or 'na' in query :
speak("yes sir ....what happend ... how may i help you ")
elif 'remind me' in query or 'yaad dilao' in query:
speak(" are you done with yours todays revision .....sir please complete it soon")
elif 'thank you' in query:
speak(" Its my pleasure sir that i was usefull")
elif 'how are you jarvis'in query or 'how are you ' in query or 'how are you doing' in query:
speak(" i am good sir ......how are you")
elif 'abe yaar ' in query or 'shit yaar ' in query or 'bhai yaar' in query or 'yaar' in query:
speak("what happened sir....is eveything ok")
elif 'sleep' in query or 'chup' in query or 'chup yaar' in query:
speak( "ok sir...taking leave ....always there to serve you ")
exit()
#code written by Mahattva Sahu
# if you guys came across with any error just comment down