def __init__(self, speak_type, command, split_num): if checkConnection() == True: self.search_query = splitJoin( command, split_num) # function to split and rejoin command self.speak_type = speak_type url = ('https://www.dictionary.com/browse/' + self.search_query + '?s=t') # combine url with search query from command r = get(url) # request page page = r.text # formatting self.soup = bs(page, 'html.parser') # parse html self.go_no_go = 'go' else: self.go_no_go = 'no'
def __init__(self, speak_type, command, split_num): if checkConnection() == True: self.search_query = splitJoin( command, split_num) # function to split and rejoin command self.speak_type = speak_type spliting = self.search_query.split(" ")[0:] search_query_with_under_scores = ("_").join(spliting) self.url = ('https://www.rottentomatoes.com/m/' + search_query_with_under_scores ) # combine url with search query from command r = get(self.url) # request page page = r.text # formatting self.soup = bs(page, 'html.parser') # parse html self.go_no_go = 'go' else: self.go_no_go = 'no'
def __init__(self, speak_type, command, split_num): if checkConnection() == True: self.search_query = splitJoin( command, split_num) # function to split and rejoin command self.speak_type = speak_type self.videolist = [] # create empty list self.url = ('https://www.youtube.com/results?search_query=' + self.search_query ) # combine url with search query from command r = get(self.url) # request page page = r.text # formatting soup = bs(page, 'html.parser') # parse html self.vids = soup.findAll(attrs={ 'class': 'yt-uix-tile-link' }) # search for class yt-uix-tile-link in html from page self.go_no_go = 'go' else: self.go_no_go = 'no'
def getVersion(): if checkConnection() == True: url = ( 'https://github.com/SavageCoder77/MARVIN_2.0/blob/master/marvin/json/marvin_version.txt' ) r = get(url) # request page page = r.text soup = bs(page, 'html.parser') # parse html vids = soup.findAll( 'td', attrs={ 'id': 'LC1', 'class': 'blob-code blob-code-inner js-file-line' } ) # search for class meter-value superPageFontColor in html from page version_marvin = vids[0].getText() print('Marvin Version ' + str(version_marvin)) return version_marvin else: speak('No internet connection couldn\'t access')
def speak(spokenString, voice): python_path = path.join('marvin-env', 'bin', 'python3') # Format Paths speak_path = path.join('marvin', 'called_files', 'pyttsx3_speak.py') # Format Paths print(spokenString) # string to speak if voice == 'female' and checkConnection() == True: if path.isfile("Speak.mp3"): remove("Speak.mp3") tts = gTTS(text=spokenString, lang='en-uk') # create string into mp3 file using gtts tts.save('Speak.mp3') # save gtts audio as Speak.mp3 if system() == 'Windows': playsound('Speak.mp3') else: proc = Popen( ['mpg321 Speak.mp3'], stdout=PIPE, stderr=PIPE, shell=True) # Popen command with terminal command arguments (out, err) = proc.communicate() # opening speak file elif voice == 'male': call([python_path, speak_path, spokenString]) else: print('No internet connection using offline speak') call([python_path, speak_path, spokenString])