def topic_search(query): topic = query.lower().replace("make", "").replace("search", "").replace("on google", "") je.speak("making the google search...") kit.search(topic) #Will perform a Google search return
def open_the_app(query): #query contains the text which is converted from speech to text #when in the jarvis.py user says 'open the' or 'close the' then control is redirected to this script #here o_t_a contains the app keywords and function is stored as a value #when any keywords matched associated operations are performed o_t_a = { "jupyter notebook": jupyter_notebook, "jupyter": jupyter_notebook, "chrome": open_chrome, "sublime": open_sublime, "news reader application": news_reader, "android studio": android_studio, "notepad": notepad, "visual studio": visual_studio, } #suppose u want to open the chrome then say open the chrome #it will check weather chrome is there in the o_t_a or not #but chrome is there ("chrome":open_chrome) in o_t_a therefore associated function will run whuch is open_chrome for each_app in o_t_a: try: if each_app in query.lower(): o_t_a[each_app](query) break except: pass else: je.speak("Sir I do not have the access of this app till now") return
def sub(query): print("subtraction function Called") result = 0 numbers = extract_numbers(query) result = numbers[0] - numbers[1] print("jarvis:" + "it's " + str(result) + ' Sir') je.speak("it's " + str(result) + ' Sir')
def main(query): response = google_images_download.googleimagesdownload() jarvis.speak("How many images of " + query + "do you want me to download") noOfImgs = int(jarvis.takeCommand()) arguments = { "keywords": query, "format": "jpg", "limit": noOfImgs, "print_urls": False, "size": "medium", "aspect_ratio": "panoramic" } try: response.download(arguments) except FileNotFoundError: arguments = { "keywords": query, "format": "jpg", "limit": noOfImgs, "print_urls": False, "size": "medium" } try: response.download(arguments) except: pass jarvis.speak("I have downloaded the images of " + query + "and stored it in the download folder, take a look of it")
def wiki_search(query): query = query.replace("tell me something about", '') result = wikipedia.summary(query) print("zenny:" + str(result)) je.speak("According to Wikipedia") je.speak(str(result)) return
def mult(query): mul = 1 print("mul function Called") numbers = extract_numbers(query) for element in numbers: mul *= int(element) else: print("jarvis:" + "it's " + str(mul) + ' Sir') je.speak("it's " + str(mul) + ' Sir')
def add(query): #Now suppose user says in the jarvis.py jarvis what is the addition of 5 and 6 #extract_numbers will extract 5 and 6 from the query and returns the list sum = 0 print("Add function Called") numbers = extract_numbers(query) for element in numbers: sum += element else: print("jarvis:" + "it's " + str(sum) + ' Sir') je.speak("Total Addition value is " + str(sum) + ' Sir')
def notepad(query): try: if "open the notepad" in query.lower(): je.speak("opening the notepad++ application") subprocess.Popen(r"C:\Program Files\Notepad++\notepad++.exe") return elif "close the notepad" in query.lower(): je.speak("closing the notepad application") os.system("TASKKILL /F /IM notepad++.exe") return except: pass
def android_studio(query): try: if "open the android studio" in query.lower(): je.speak("opening the android studio application") subprocess.Popen( r"C:\Program Files\Android\Android Studio\bin\studio64.exe") return elif "close the android studio" in query.lower(): je.speak("closing the android studio application") os.system("TASKKILL /F /IM studio64.exe") return except: pass
def open_sublime(query): try: if "open the sublime" in query.lower(): je.speak("opening the sublime application") subprocess.Popen( r"C:\Program Files\Sublime Text 3\sublime_text.exe") return elif "close the sublime" in query.lower(): je.speak("closing the sublime application") os.system("TASKKILL /F /IM sublime_text.exe") return except: pass
def news_reader(query): try: if "open the news reader" in query.lower(): je.speak("opening the news reader application") subprocess.Popen( r"C:\Users\Dell\Desktop\LearnPython\web Scrapping\news reader\dist\NewsReader.exe" ) return elif "close the news reader" in query.lower(): je.speak("closing the news reader application") os.system("TASKKILL /F /IM NewsReader.exe") return except: pass
def visual_studio(query): try: if "open the visual studio" in query.lower(): je.speak("opening the visual studio code application") subprocess.Popen( r"C:\Users\Dell\AppData\Local\Programs\Microsoft VS Code\Code.exe" ) return elif "close the visual studio" in query.lower(): je.speak("closing the visual studio code application") os.system("TASKKILL /F /IM Code.exe") return except: pass
def open_chrome(query): try: #if user says open the chrome then below if block will run for opeining the chrome if "open" in query.lower(): je.speak("opening the chrome application") #here pecify the path of the chrome.exe of your chrome browser #u can get this path from properties and copy the Target path of the application subprocess.Popen( "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") return elif "close the chrome" in query.lower(): #here if close the chrome is there in the query then it will close the browser je.speak("Closing the chrome application") os.system("TASKKILL /F /IM chrome.exe") return except: pass
def open_youtube(query): try: query = query.replace('jarvis', '') if "stop the music" in query.lower( ) or "music band karo" in query.lower(): je.speak("Stoping the music sir") os.system("TASKKILL /F /IM chrome.exe") return os.system("TASKKILL /F /IM chrome.exe") except: pass query = query.replace("open youtube", "").replace("drop my needle", "").replace("play", '') je.speak("Playing " + query + " Sir") kit.playonyt(query) return
def wishMe(): hour = int(datetime.datetime.now().hour) if hour >= 0 and hour < 12: jarvis.speak("Good Morning") elif hour >= 12 and hour < 18: jarvis.speak("Good Afternoon") else: jarvis.speak("Good evening") jarvis.speak("I am Jarvis sir! please tell me how may i help you")
def weather_forecast(query): try: city_name = "vasai road" #replace it with your city api_id = 'your api id' #just enter your api id here encloded in '' url = f"http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_id}&units=metric" res = requests.get(url) data = res.json() je.speak("temperature is" + str(data['main']['temp']) + 'degree celsius') je.speak("humidity is" + str(data['main']['humidity']) + ' percent') je.speak(str(data['clouds']['all']) + ' percent clouds will be there') je.speak('wind speed is ' + str(data['wind']['speed']) + 'kilometer per hour') except: pass
def main(query): collection = json.load(open("collection.json")) query = query.lower() if query in collection: meaning = collection[query] if type(meaning) == list: for item in meaning: jarvis.speak(query +"means" +item) else: jarvis.speak(meaning) else: jarvis.speak("No such word")
def age(): jarvis.speak("You know it's rude to ask an assistant their age") jarvis.speak("Any how..") dob = "01/05/2019" dob = datetime.strptime(dob, '%d/%m/%Y') jarvis.speak("Here are your age statistics...") jarvis.speak("%d Years or" % ((datetime.today() - dob).days / 365)) jarvis.speak("%d Months or" % ((datetime.today() - dob).days / 30)) jarvis.speak("%d Days or" % ((datetime.today() - dob).days * 24)) jarvis.speak("%d Minutes or" % ((datetime.today() - dob).days * 1440)) jarvis.speak("%d Seconds or" % ((datetime.today() - dob).days * 86400)) jarvis.speak("Ohh God it's damn big to calculate") jarvis.speak("I think you are satisfied with my age")
def specialDay(): if datetime.date(2022, 6, 26) == datetime.date.today(): wishList = [ "Happy birthday sir", playsound.playsound("BirthdaySong.mp3") ] speak(random.Random(wishList)) # webbrowser.open("https://music.youtube.com/watch?v=pk21s6tUjGY&list=RDAMVMpk21s6tUjGY") elif datetime.date(2021, 8, 19) == datetime.date.today(): notification.notify(title="Ankita's Birthday", message="Wish them", app_icon="E:\Jarvis AI\icon.ico", timeout=5) # speak("Today is Ankita's birthday.") elif datetime.date(2021, 3, 29) == datetime.date.today(): notification.notify(title="Today is Holy", message="Happy Holy", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Holli sir.") elif datetime.date(2022, 8, 15) == datetime.date.today(): notification.notify(title="Independence Day", message="Happy Independence Day", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Independence Day sir") elif datetime.date(2021, 10, 15) == datetime.date.today(): notification.notify(title="Dussehra", message="Happy Dussehra sir", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Dussehra sir") elif datetime.date(2021, 11, 4) == datetime.date.today(): notification.notify(title="Diwali", message="Happy Diwali", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Diwali sir") elif datetime.date(2021, 11, 10) == datetime.date.today(): notification.notify(title="Chhat Puja", message="Happy Chhat puja", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Chhat puja sir.") elif datetime.date(2022, 1, 26) == datetime.date.today(): notification.notify(title="Republic Day", message="Happy Republic Day", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Republic day sir") elif datetime.date(2022, 4, 26) == datetime.date.today(): notification.notify(title="Jarvis's Birthday", message="Today is Birthday of your Jarvis's AI.", app_icon="E:\Jarvis AI\icon.ico", timeout=5) speak("Happy Birthday to me")
def shutdown_pc(query): if "shutdown" in query.lower() and "pc" in query.lower(): je.speak("shutting Down the pc in 10 seconds") kit.shutdown(time=10) return
def restart_pc(query): if "restart" in query.lower() and "pc" in query.lower(): je.speak("restarting the pc in 10 seconds") os.system("shutdown /r /t 1") return
def tell_story(): story1 = """Time travel is the concept of movement between certain points in time, analogous to movement between different points in space by an object or a person, typically using a hypothetical device known as a time machine. Time travel is a widely-recognized concept in philosophy and fiction. The idea of a time machine was popularized by H. G. Wells' 1895 novel The Time Machine. It is uncertain if time travel to the past is physically possible. Forward time travel, outside the usual sense of the perception of time, is an extensively-observed phenomenon and well-understood within the framework of special relativity and general relativity. However, making one body advance or delay more than a few milliseconds compared to another body is not feasible with current technology. As for backwards time travel, it is possible to find solutions in general relativity that allow for it, but the solutions require conditions that may not be physically possible. Traveling to an arbitrary point in spacetime has a very limited support in theoretical physics, and usually only connected with quantum mechanics or wormholes, also known as Einstein-Rosen bridges.""" story2 = """The Adventures of Sherlock Holmes is a collection of twelve short stories by Arthur Conan Doyle, featuring his fictional detective Sherlock Holmes. It was first published on 14 October 1892; the individual stories had been serialised in The Strand Magazine between July 1891 and June 1892. The stories are not in chronological order, and the only characters common to all twelve are Holmes and Dr. Watson. The stories are related in first-person narrative from Watson's point of view. In general the stories in The Adventures of Sherlock Holmes identify, and try to correct, social injustices. Holmes is portrayed as offering a new, fairer sense of justice. The stories were well received, and boosted the subscriptions figures of The Strand Magazine, prompting Doyle to be able to demand more money for his next set of stories. The first story, "A Scandal in Bohemia", includes the character of Irene Adler, who, despite being featured only within this one story by Doyle, is a prominent character in modern Sherlock Holmes adaptations, generally as a love interest for Holmes. Doyle included four of the twelve stories from this collection in his twelve favourite Sherlock Holmes stories, picking "The Adventure of the Speckled Band" as his overall favourite. """ story3 = """All of the stories within The Adventures of Sherlock Holmes are told in a first-person narrative from the point of view of Dr. Watson, as is the case for all but four of the Sherlock Holmes stories.[6] The Oxford Dictionary of National Biography entry for Doyle suggests that the short stories contained in The Adventures of Sherlock Holmes tend to point out social injustices, such as "a king's betrayal of an opera singer, a stepfather's deception of his ward as a fictitious lover, an aristocratic crook's exploitation of a failing pawnbroker, a beggar's extensive estate in Kent."[1] It suggests that, in contrast, Holmes is portrayed as offering a fresh and fair approach in an unjust world of "official incompetence and aristocratic privilege".[1] The Adventures of Sherlock Holmes contains many of Doyle's favourite Sherlock Holmes stories. In 1927, he submitted a list of what he believed were his twelve best Sherlock Holmes stories to The Strand Magazine. Among those he listed were "The Adventure of the Speckled Band" (as his favourite), "The Red-Headed League" (second), "A Scandal in Bohemia" (fifth) and "The Five Orange Pips" (seventh).[7] The book was banned in the Soviet Union in 1929 because of its alleged "occultism",[8] but the book gained popularity in a black market of similarly banned books, and the restriction was lifted in 1940""" story = [story1, story2, story3] jarvis.speak( "THe stories available are Timetravel, SHerlock holmes, and summary of sherlock holmes" ) jarvis.speak("WHich story do u want to read") while True: query = jarvis.takeCommand().lower() if 'time' in query: print(story[0]) jarvis.speak("Do you want to search any word") if 'yes' in query: jarvis.speak( "say the word which u remember, so that i can search for u" ) word = '' if word in query: findWord(story1, word) jarvis.speak("Is this your search word?") ch = '' while (ch): if 'yes' in query: jarvis.speak("Happy reading") elif 'no' in query: jarvis.speak("searching..") new = findWord(story2, word) findWord(new, word) jarvis.speak("Is this your search word?") ch = jarvis.takeCommand() else: pass else: pass else: jarvis.speak("Happy reading") time.sleep(10)
def operation(): while True: query = jarvis.takeCommand().lower() #Reading a Wikipedia according to user want if 'wikipedia' in query: jarvis.speak('Searching wikipedia...') query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) jarvis.speak("According to wikipedia") print(results) jarvis.speak(results) elif 'calculation' in query: jarvis.speak('What operation do you want to perform') text = jarvis.takeCommand().lower() def get_operation(op): return { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.__truediv__ }[op] def perform(op1, oper, op2): op1, op2 = int(op1), int(op2) return get_operation(oper)(op1, op2) print(perform(*(text.split()))) jarvis.speak(perform(*(text.split()))) #Telling the time of system to user elif 'time' in query: strTime = datetime.datetime.now().strftime("%H:%M:%S") jarvis.speak("sir the Time is") print(strTime) jarvis.speak(strTime) #open a code according want path u pass elif 'open' in query: codepath = '/usr/local/share' os.system('explore codepath:\bin{}'.format( query.replace('Open', ''))) continue #search from google open the querie in google elif 'search' in query: jarvis.speak('yes sir what you want to search') print('yes sir what you want to search') text = jarvis.takeCommand().lower() try: #chrome_path = '/usr/bin/firefox /usr/lib/firefox/ etc/firefox /usr/share/man/man1/firefox.1.gz %s' print('opening sir...') jarvis.speak('opening sir') text_path = 'https://www.google.co.in/search?q=' + text webbrowser.open(text_path) break except: print('Something went wrong') break elif 'find' in query: jarvis.speak('yes sir what operation do you want to perform') text = jarvis.takeCommand().lower() Cal.operations(text) else: if 1: # speak('what operation want\'s you') # print("what operation want\'s you...") # w2n.word_to_num(query) for word in query.split(' '): if word in Cal.operations.keys(): try: # w2n.word_to_num(query) #l = Cal.extract_numbers_from_text(query) r = Cal.operations[word]() #(l[0], l[1] print() break except: print("Something is wrong please retry") break else: jarvis.speak('sir this is not in my database') print('sir this is not in my database')
def jupyter_notebook(query): if 'open' in query.lower() and 'jupyter' in query.lower(): je.speak("opening the jupyter notebook") os.system('cmd /k "jupyter notebook"') return