def joke(): global deviceLanguage global soundDirectory res = requests.get('https://icanhazdadjoke.com/', headers={"Accept": "application/json"}) if res.status_code == requests.codes.ok: print(str(res.json()['joke'])) tts = gTTS(str(res.json()['joke']), deviceLanguage) tts.save(os.path.join(soundDirectory, "joke.mp3")) playMp3(os.path.join(soundDirectory, "joke.mp3")) else: # engine.say('oops!I ran out of jokes') # engine.runAndWait() pass
def assistant(command): global volumeLevel global youtube_open global youtube_tab global deviceName global currentDirectory global driver global scroll global scroll_num global google_firebase #ROOT COMMAND if command == "hey " + deviceName or command == deviceName: playMp3(currentDirectory + r"\sounds\answer.mp3") #Home automation elif "unlock" in command: google_firebase.child("door").set("unlock") elif "lock" in command: google_firebase.child("door").set("lock") elif ("on" in command) and ("kitchen" in command): google_firebase.child("device1").set("on") elif ("off" in command) and ("kitchen" in command): google_firebase.child("device1").set("off") elif ("on" in command) and ("living room" in command): google_firebase.child("living-room").set("on") elif ("off" in command) and ("living room" in command): google_firebase.child("living-room").set("off") #Internet Commands elif "incognito" == command or "incognito mode" == command: incognitoMode() elif "click" in command: try: link = driver.find_element_by_link_text(command[5:].strip().upper()) link.click() except Exception as e: print(e) try: link = driver.find_element_by_link_text(command[5:].strip().lower()) link.click() except Exception as e: print(e) try: link = driver.find_element_by_link_text(command[5:].strip().capitalize()) link.click() except Exception as e: print(e) try: clickHref(command[5:]) except Exception as e: print(e) elif command == "go back": driver.back() elif command == "go forward": driver.forward() elif "refresh" in command: driver.refresh() elif command == "scroll down": try: driver.execute_script("window.scrollTo(0, " + scroll + ");") except Exception as e: print(e) scroll_num += 370 scroll = str(scroll_num) elif command == "scroll up": if scroll_num > 370: scroll_num -= 370 scroll = str(scroll_num) try: print("window.scrollTo(0, " + scroll + ");") driver.execute_script("window.scrollTo(0, " + scroll + ");") except Exception as e: print(e) elif command == "minimize window": try: driver.set_window_position(-10000, 0) except: pass elif command == "maximize window": try: driver.maximize_window() except: pass #Internet--YouTube elif ("youtube" in command[0:7]) and ("search youtube" not in command) and ("youtube search" not in command): youtube(command) elif "play" in command[0:4]: youtube(command) # elif command in youtube_commands: # YouTubeCommands(command) elif "full screen" in command: try: classname = 'ytp-fullscreen-button' button = driver.find_element_by_class_name(classname).click() except Exception as e: print(e) elif command == "download video": downloadYouTube(youtube_tab) elif command == "download music": download_thread = threading.Thread(target=YouTubeToMp3, args=()) download_thread.start() #Setting Commands elif command == "change voice" or command == "change accent": changeAccent() elif command == "change name" or command == "name change": changeDeviceName() elif command[0:4] == "open": openApp(command[4:]) #Joke Teller elif 'joke' in command or "tell me a joke" in command: joke() elif command == "stop": stop() elif "google" in command[0:7]: googler(command[7:]) # #Computer Commands # elif "sleep" in command: # print("YEET") # try: # os.system("shutdown.exe /h") # except Exception as e: # print(e) elif "decrease volume" in command or "lower volume" in command: try: volume.SetMasterVolumeLevel(-20, None) # engine.say("Volume decreased") # engine.runAndWait() except: pass elif "increase volume" in command or "raise volume" in command: try: print("Vol increased") volume.SetMasterVolumeLevel(-3, None) print(volume.GetMasterVolumeLevel()) # engine.say("Volume increased") # engine.runAndWait() except: pass elif command == "max volume": try: volume.SetMasterVolumeLevel(0, None) print(volume.GetMasterVolumeLevel()) # engine.say("Volume increased") # engine.runAndWait() except: pass elif command == "mute" or command == "be quiet": try: volume.SetMasterVolumeLevel(-100, None) print(volume.GetMasterVolumeLevel()) # engine.say("Volume increased") # engine.runAndWait() except: pass elif command == "mid volume": try: volume.SetMasterVolumeLevel(-10, None) print(volume.GetMasterVolumeLevel()) # engine.runAndWait() except: pass else: pass
def assistant(command): global volumeLevel global youtube_open global youtube_tab global deviceName global currentDirectory global driver global scroll global scroll_num # ROOT COMMAND if command == "hey " + deviceName or command == deviceName: stop() playMp3(currentDirectory + r"\sounds\answer.mp3") # Internet Commands elif "click" in command: try: link = driver.find_element_by_link_text( command[5:].strip().upper()) link.click() except Exception as e: print(e) try: link = driver.find_element_by_link_text( command[5:].strip().lower()) link.click() except Exception as e: print(e) try: link = driver.find_element_by_link_text( command[5:].strip().capitalize()) link.click() except Exception as e: print(e) elif command == "go back": driver.back() elif command == "go forward": driver.forward() elif command == "scroll down": try: driver.execute_script("window.scrollTo(0, " + scroll + ");") except Exception as e: print(e) scroll_num += 370 scroll = str(scroll_num) elif command == "scroll up": if scroll_num > 370: scroll_num -= 370 scroll = str(scroll_num) try: print("window.scrollTo(0, " + scroll + ");") driver.execute_script("window.scrollTo(0, " + scroll + ");") except Exception as e: print(e) elif command == "minimize window": try: driver.set_window_position(-10000, 0) except: pass elif command == "maximize window": try: driver.maximize_window() except: pass # Internet--YouTube elif ("youtube" in command[0:7]) and ("search youtube" not in command) and ("youtube search" not in command): youtube(command) elif command in youtube_commands: YouTubeCommands(command) elif command == "download video": downloadYouTube(youtube_tab) elif command == "download music": download_thread = threading.Thread(target=YouTubeToMp3, args=()) download_thread.start() # Setting Commands elif command == "change voice" or command == "change accent": changeAccent() elif command == "change name" or command == "name change": changeDeviceName() elif command[0:4] == "open": openApp(command[4:]) # Joke Teller elif 'joke' in command or "tell me a joke" in command: joke() elif command == "stop": stop() elif "google" in command[0:7]: googler(command[7:]) elif command == "goodbye " + deviceName: exit(0) elif command not in every_command and command != "": if youtube_open == False: pass else: pass # -------------------------------------------------------------VOLUME SETTINGS elif "decrease volume" in command or "lower volume" in command: try: volume.SetMasterVolumeLevel(-20, None) # engine.say("Volume decreased") # engine.runAndWait() except: pass elif "increase volume" in command or "raise volume" in command: try: volume.SetMasterVolumeLevel(-3, None) print(volume.GetMasterVolumeLevel()) # engine.say("Volume increased") # engine.runAndWait() except: pass elif command == "max volume": try: volume.SetMasterVolumeLevel(0, None) print(volume.GetMasterVolumeLevel()) # engine.say("Volume increased") # engine.runAndWait() except: pass elif command == "mute" or command == "be quiet": try: volume.SetMasterVolumeLevel(-100, None) print(volume.GetMasterVolumeLevel()) # engine.say("Volume increased") # engine.runAndWait() except: pass elif command == "mid volume": try: volume.SetMasterVolumeLevel(-10, None) print(volume.GetMasterVolumeLevel()) # engine.runAndWait() except: pass else: pass