def utilityCommands(text): if (text == 'take a note'): note_text = ap.listen() if (note_text != ""): home = expanduser("~") file = open(home + '/' + 'sarah-note.txt', 'a') file.write(time.ctime()) file.write(" :- ") file.write(note_text) file.write("\n") ap.say("Note saved in your home directory") else: ap.say("Could not understand note text")
def wishUser(userName): hour = int(datetime.datetime.now().hour) if hour >= 0 and hour < 12: ap.say("Good Morning " + userName + "! What can I do for you?") elif hour >= 12 and hour < 18: ap.say("Good Afternoon " + userName + "! What can I do for you?") else: ap.say("Good Evening " + userName + "! What can I do for you?")
def queryResponder(request_input, answers): if (request_input['type'] == 'text_queries'): answer = answers[request_input['index']] reply = answer.replace("{assistantName}", request_input['assistantName']) reply = reply.replace("{userName}", request_input['userName']) ap.say(reply) qc.queryCommands(request_input['text']) bc.browserCommands(request_input['text'], answer) uc.utilityCommands(request_input['text']) elif (request_input['type'] == 'command_queries'): answer = answers[request_input['index']] ap.say(answer) qc.queryCommands(request_input['text']) elif (request_input['type'] == 'browser_queries'): answer = answers[request_input['index']] bc.browserCommands(request_input['text'], answer) else: ap.say('Sorry, i didn\'t get ' + request_input['text'])
def browserCommands(text, answer): if (text == "open youtube"): webbrowser.open("http://youtube.com") elif (text == "open google"): webbrowser.open("http://google.com") elif (text == "open stack overflow"): webbrowser.open("http://stackoverflow.com") elif ("search youtube" in text): query = text.replace("search youtube", "").strip() if (query == ""): ap.say("Sorry! I cannot find anything to search for...") else: answer = answer.replace("{searchText}", query) ap.say(answer) webbrowser.open("https://www.youtube.com/results?search_query=" + query) elif ("search google" in text): query = text.replace("search google", "").strip() if (query == ""): ap.say("Sorry! I cannot find anything to search for...") else: answer = answer.replace("{searchText}", query) ap.say(answer) webbrowser.open("https://www.google.com/search?q=" + query) elif ("search stackoverflow" in text): query = text.replace("search stackoverflow", "").strip() if (query == ""): ap.say("Sorry! I cannot find anything to search for...") else: answer = answer.replace("{searchText}", query) ap.say(answer) webbrowser.open("https://stackoverflow.com/search?q=" + query)
def queryCommands(text): if(text == "powerpoint"): os.system("libreoffice --draw") elif(text == "excel"): os.system("libreoffice --calc") elif(text == "writer"): os.system("libreoffice --writer") elif(text == "time"): ap.say(time.ctime()) elif(text == "vs code"): os.system("code") elif(text == "joke"): ap.say(pyjokes.get_joke()) elif("wikipedia" in text): query = text.replace("wikipedia", "").strip() if(query == ""): ap.say("Sorry! I cannot find anything to search for...") else: results = wikipedia.summary(query, sentences=1) ap.say("According to Wikipedia...") print(results) ap.say(results) elif(text == "shutdown system"): confirm = ap.listen() if("yes" in confirm): os.system("shutdown -h +1") ap.say("Shutting down in 1 minute") else: ap.say("Aborting Shutdown..") elif(text == "restart system"): confirm = ap.listen() if("yes" in confirm): os.system("shutdown -r +1") ap.say("Restarting in 1 minute") else: ap.say("Aborting Restart..") elif(text in ["cancel shutdown", "cancel restart"]): os.system("shutdown -c")