def get_news(topic): query = topic.replace(' ', '+') link = "https://www.bing.com/news/search?q=" + query + "&FORM=HDRSC6" r = requests.get(link) soup = BeautifulSoup(r.content, 'html.parser') #print(soup.prettify()) news_elements = soup.find_all("a", class_="title") """element_url = soup.find_all("a") for url in element_url: print(url)""" num_links = len(news_elements) if (num_links < 1): print("Could not find any news") return -1 """for element in news_elements: print(str(element))""" itr = 0 text_speech.say("Opening news about " + topic + " in your browser") while ((itr < 3) and (itr < num_links)): news_url = news_elements[itr]["href"] """print(news_url) article = Article(news_url) article.download() article.parse() print(article.title) summary = str(article.summary) print(len(summary)) itr+=1""" itr += 1 web_browser.open_link(news_url)
def translate(): trans = Translator() text_speech.say("Enter a string in any language") in_str = raw_input() out_str = trans.translate(in_str) print "The input language is: " + LANGUAGES[ out_str.src] + "\nIts translation in English: " + out_str.text
def download_song(topic): #try: top_res = get_top_result(topic) #os.chdir('../Downloads') ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }], 'quiet': True, 'restrictfilenames': True, 'outtmpl': home + '/Desktop/%(title)s.%(ext)s' } ydl = youtube_dl.YoutubeDL() text_speech.say("Downloading " + topic + " Please Wait.") ydl.download(['https://www.youtube.com' + top_res]) text_speech.say(topic + " downloaded. Check the downloads directory.") #os.chdir('../src') #except: # print("OOPS Song Could Not Be Downloaded") #stream_video("Fwu kehlani") #download_video("Really something by hector gahan")
def find_on_map(topic): try: text_speech.say("Opening " + topic + " on google maps") webbrowser.open("https://www.google.nl/maps/place/" + topic + "/&") except: text_speech.say("Some error occured.") #find_on_map("Siwa")
def stream_video(topic): try: top_res = get_top_result(topic) if (str(top_res) == "-1"): return -1 text_speech.say("Streaming Video In Your Browser") webbrowser.open('https://www.youtube.com' + top_res) except: text_speech.say("Sorry Video Could Not Be streamed")
def chat(): while True: user_input = raw_input('You : ') # print(user_input) if user_input == str('quit'): break try: response = chatbot.get_response(user_input) print(response) text_speech.say(str(response)) except (KeyboardInterrupt, EOFError, SystemExit): break
def weather_loc(location): text_speech.say("weather and forecast of " + location) weather = Weather(unit=Unit.CELSIUS) location = weather.lookup_by_location(location) condition = location.condition #print(condition.text) print("Last updated " + condition.date + " Condition :- " + condition.text) forecasts = location.forecast #print(len(forecasts)) for forecast in forecasts: print("On date " + forecast.date + " Condition :- " + forecast.text + " High :- " + forecast.high + " Low :- " + forecast.low)
def open_wiki(topic): try: page = wikipedia.page(topic) except: text_speech.say("Sorry, Some error occured. Are you sure this topic is on wikipedia") return 1 text_speech.say('Getting the url') link = page.url web_browser.open_link(link) return 0 #open_wiki('Messi')
def get_top_result(topic): try: text_speech.say("Finding " + topic) topic_url = topic.replace(' ', '+') url = 'https://www.youtube.com/results?search_query=' + topic_url r = requests.get(url) soup = BeautifulSoup(r.content, "html.parser") all_videos = soup.findAll('div', {'class': 'yt-lockup-video'}) top_res = all_videos[0].find('a')['href'] return top_res except: text_speech.say("Error Occured while finding a match") return -1
def find_all(name, path): text_speech.say("Searching Your Desktop") count = 0 result = [] for root, dirs, files in os.walk(path): if name in files: match = os.path.join(root, name) result.append(match) webbrowser.open(match) count += 1 if (count >= 1): break text_speech.say(str(len(result)) + " results found.") #find_all("exp_sky.jpg","/home")
def listen(): r = sr.Recognizer() with sr.Microphone() as source: r.adjust_for_ambient_noise(source) text_speech.say("Say something!") audio = r.listen(source, timeout=8) input_textr="" # recognize speech using Sphinx try: #print("Sphinx thinks you said " + r.recognize_sphinx(audio)) input_textr = r.recognize_google(audio) print("You said :- " + input_textr) return input_textr except sr.UnknownValueError: text_speech.say("Could not understand audio") except sr.RequestError as e: print("Error; {0}".format(e))
def download_video(topic): try: small_methods.directory_manage('Downloads') os.chdir('Downloads') top_res = get_top_result(topic) ydl_opts = { 'format': 'bestvideo/best', 'quiet': True, 'restrictfilenames': True, } ydl = youtube_dl.YoutubeDL() ydl.download(['https://www.youtube.com' + top_res]) #except: os.chdir('../') text_speech.say("Video Downloaded. Check Your Downloads directory.") except: text_speech.say("Video Could not be Downloaded")
def play(): text_speech.say("What do you want to listen:") song = raw_input() query = "play " + song + " sound cloud" for url in search(query, tld="com", num=1, stop=1, pause=2): wb.open_new_tab(url)
def open_link(link): try: webbrowser.open(link) except: text_speech.say("Sorry, Some error occured while opening the link.")
import img_srch import speech_text import dev_handle import get_weather import you_down import time import play_music import translator #import translator import get_map import os #import gmail_virtAss sys.path.insert(0, 'chat_dir') import dumb_chatbot text_speech.say("Hello, How may I help You?") text_input = raw_input() while (text_input != "exit"): if (text_input == "lock device"): try: dev_handle.lock_device() except: text_speech.say("Sorry. An error was encountered.") elif (text_input == "restart device"): try: text_speech.say("Restarting device.") time.sleep(5) dev_handle.restart() break