def news(str): global i if i == 0: spacek(f"ofcures {str} which news you want to listen") else: spacek(f"which news you want to listen{str}") try: s = takecommend().lower() s = s.replace('about', "") spacek("which page you want ot listen") s2 = int(takecommend()) googlenews = GoogleNews() googlenews = GoogleNews('en', "2") # here you can use d which is denoted for how much linw you want to lesiten googlenews.search(s) googlenews.getpage(s2) googlenews.result() spacek(f" {str} here is news about ") spacek(s) print(googlenews.gettext()) spacek(googlenews.gettext()) except Exception as s: spacek(f"could not understand {str} what did you say say it again") i = 1 news(str)
def todaysNews(str): googlenews = GoogleNews() googlenews = GoogleNews('en', 'd') googlenews.search(str) googlenews.getpage(1) googlenews.result() g = googlenews.gettext() return g
def news(): topic = entry.get() googlenews = GoogleNews() googlenews = GoogleNews('en', 'd') googlenews.search(topic) googlenews.getpage() googlenews.result() a = googlenews.gettext() output.insert(END, a) speak = Dispatch( "SAPI.SpVoice" ) #calling this dispatch method helps to interact with Microsoft Speech SDK to speak speak.Speak(a)
def getNews(text): googlenews = GoogleNews("en", "m" ) #Parameters: language and timeframe (day, month, year) googlenews.search(text) googlenews.getpage(1) #first Result Page headlines = googlenews.gettext() #only show Headlines (pictures or links are also available) #convert to string, Because Wordcloud expects string like object text = ' '.join([str(elem) for elem in headlines]) generateWordCloud(text) googlenews.clear() return
def news(): speak("What kind of news would you like to hear ?") type = takeCommand() googleNews = GoogleNews() googleNews = GoogleNews(lang = 'en') googleNews.search(type) # will search the kind we want to hear googleNews.getpage(1) # page number of news googleNews.result() list = googleNews.gettext() #print(list) if len(list) > 0: speak(random.choice(list)) else: speak("No news related to this topic.")
async def search(ctx, *, message): googlenews = GoogleNews(lang='en', period='d') googlenews.search(message) result = googlenews.gettext() embed = discord.Embed() embed.colour = discord.Colour.from_rgb(255, 225, 135) embed.set_author(name="Google NEWS", icon_url="https://i.imgur.com/tDLGRiT.jpg") embed.set_footer( text="Data from Google News | WallSt Bot made by Bruno Lazaro.") embed.add_field( name=f"{message} News", value= (f'{result[1]}\n\n{result[2]}\n\n{result[3]}\n\n{result[4]}\n\n{result[5]}\n\n{result[6]}' ), inline=False) await ctx.send(embed=embed) googlenews.clear()
def run(start_date, end_date, keyword, file, mail, importance): #find relevant news articles within given timeframe googlenews = GoogleNews() googlenews = GoogleNews(lang='en') googlenews = GoogleNews(start=start_date, end=end_date) googlenews.search(keyword) res = googlenews.result() googlenews.result() headlines = googlenews.gettext() links = googlenews.get__links( ) #note that documentation has this as googlenews.getlinks() so it might change #get page url results = articleReader(links, headlines, keyword) run.df = pd.DataFrame(results) if run.df.shape[0] > importance: run.df = run.df.iloc[0:importance] return run.df
from GoogleNews import GoogleNews from datetime import date, datetime googlenews = GoogleNews() today = date.today() date = today.strftime("%d/%m/%Y") googlenews = GoogleNews(lang='en') googlenews = GoogleNews(period='d') googlenews.search(' ') news = googlenews.gettext() links = googlenews.get__links() #googlenews.getpage(1) #result = googlenews.result() for n in range(len(news)): print(news[n]) #print(links[n]) ''' for n in range(len(result)): print(n) for index in result[n]: print(index, '\n', result[n][index]) '''
gnews = GoogleNews(lang='en') run = True print('============\nGOOGLE NEWS\n============') main_topic = input('Choose a topic: ') while run: try: gnews.search(main_topic) for n, result in enumerate(gnews.result()): print(n, result['title']) ## choose which article to pick article = input('\nChoose an article by its main index or choose [all] to visualize all links: ') if article == 'all': [print(f'{n}: {new}') for n, new in enumerate(gnews.gettext())] print('--') [print(f'{n}: {link}') for n, link in enumerate(gnews.get__links())] else: article = int(article) print(f'Article - Title: {gnews.gettext()[article]}') list_artcl = gnews.gettext() print(f'Article - Link: {gnews.get__links()[article]}') list_links = gnews.get__links() print('==========================================================================\n') go_further = input('DO you want to read other articles? (y/n) ').lower() if go_further == 'y' or go_further == 'yes': gnews.clear() ## before going in loop, needs to clears the article list else: run = False ## break the loop
elif 'sad' in query: speak( "Don't worry It's okay to be sad for making your mood better i will play a song for you" ) aw = "alan walker faded lyrics" kit.playonyt(aw) elif 'news' in query: gn = GoogleNews('en', 'd') speak("which topic sir") gn.search(takeCommand().lower()) speak("let me fetch the details") gn.getpage(1) gn.result() speak(gn.gettext()) elif 'thanks' in query or 'thank you' in query: speak("YOU ARE WELCOME SIR") elif 'battery status' in query: speak("Let me check") battery = psutil.sensors_battery() percentage = battery.percent if percentage >= 70: speak( f"you have {percentage} percentage left we are fresh and ready to go" ) elif percentage >= 40: speak( f"you have {percentage} percentage left.little less but okay")
def start_func(): while True: query = takeCommand().lower() # Logic for executing tasks based on query if 'wikipedia' in query: try: speak("What do you want to search?") query = takeCommand() print('Searching Wikipedia... Please Wait') speak('Searching Wikipedia... Please Wait') results = wikipedia.summary(query, sentences=1) print("According to Wikipedia: " + results) speak("According to Wikipedia" + results) except Exception as e: print(e) speak("Sorry. I am not able to find this on wikipedia") elif "what can you do" in query or "what you can do" in query: speak("I can do many tasks for you... ") speak( "I can play a song or open facebook and youtube... I can read news headlines for you Sir!" ) speak( "I can also send emails... or if you want to search any thing on google and wikipedia... i can also do it for you" ) elif 'news' in query: try: speak("Which topic would you like to hear") query = takeCommand() print('Scrapping news for you... Please Wait') speak('Scrapping news for you... Please Wait') googlenews = GoogleNews() googlenews = GoogleNews('en', 'd') googlenews.search(query) googlenews.result() news = googlenews.gettext() print(news) speak(news) except Exception as e: print(e) speak("Sorry. I am not able to find news on this topic") elif 'google' in query: try: speak("What do you want to search?") query = takeCommand() print('Searching Google... Please Wait') speak('Searching Google... Please Wait') results = webbrowser.open("https://www.google.com/search?q=" + (query)) speak('Opening Google...') except Exception as e: print(e) speak("Sorry. I am not able to find this on google") elif 'open youtube' in query: webbrowser.open("www.youtube.com") elif 'open stackoverflow' in query: webbrowser.open("www.stackoverflow.com") elif 'open facebook' in query: webbrowser.open("www.facebook.com") elif 'the time' in query: strTime = datetime.datetime.now().strftime("%I:%M %p") speak("Sir, the time is " + (strTime)) elif 'date' in query: current_date = datetime.date.today().strftime("%d/%m/%Y") speak(current_date) elif 'send email' in query: try: speak("What should I say?") content = takeCommand() to = "*****@*****.**" sendEmail(to, content) speak("Email has been sent!") except Exception as e: print(e) speak("Sorry. I am not able to send this email") elif 'how are you' in query: speak( "I am always good Sir, Thanks for asking... now a days people dont really ask this from a machine... haa haa" ) elif 'your name' in query: speak("My name is jarvis, an AI assistant!") elif 'song' in query: playsound.playsound('snowmen.mp3') elif "remember this" in query or "make a note" in query or "write down" in query: speak("What would you like me to remember?") query = takeCommand() note(query) print("Making a note for you") speak("I've made a note of that.") elif "open the notes" in query or "open notes" in query or "my notes" in query: os.startfile("H:\\Python\\notes") elif "stop now" in query or "goodbye" in query: speak("Come again good byeee") break
from GoogleNews import GoogleNews from bs4 import BeautifulSoup import requests googlenews = GoogleNews() googlenews.setlang('cn') googlenews.setperiod('d') googlenews.setencode('utf-8') googlenews.clear() x = input("請輸入要搜尋的關鍵字,將為你搜集相關字詞內容:") googlenews.search(x) alldata = googlenews.result() result = googlenews.gettext() links = googlenews.get_links() # print(type(result)) # print(len(result)) # print(alldata) print() for n in range(len(result)): print(result[n]) print(links[n]) df = pd.DataFrame({'標題': result, '連結': links}) url = df['連結'][0] print(url)
def loop(): try: #Recognising the voice with sp.Microphone() as source: print('Hey... Adio here ') speak('Hey..adio here? how can i help u') voice=hear.listen(source) command = hear.recognize_google(voice) command = command.lower() print(command,'...') #Playing songs/videos on youtube if 'play' in command: command=command.replace('play','') print('playing'+command) pwk.playonyt(command) #wikipedia elif 'who' in command: command=command.replace('who is','') wiki=wk.summary(command,sentences=1) print(wiki) speak(wiki) #date and time using datetime library elif 'date' in command: date=dt.datetime.now().strftime('%d %B %Y %A') print(date) speak(date) elif 'time' in command: time=dt.datetime.now().strftime('%H %M %p') print(time) speak(time) #automate to shop on amazon elif 'amazon' in command: command=command.replace('on amazon','') url='https://www.amazon.in/' driver=webdriver.Chrome(ChromeDriverManager().install()) driver.get(url) driver.set_page_load_timeout(10) driver.find_element_by_xpath('//*[@id="twotabsearchtextbox"]').send_keys(command); search=driver.find_element_by_xpath('//*[@id="nav-search-submit-text"]/input') search.click() elif 'flipkart' in command: command=command.replace('on flipkart','') url='https://www.flipkart.com/' driver=webdriver.Chrome(ChromeDriverManager().install()) driver.get(url) driver.set_page_load_timeout(10) driver.find_element_by_xpath('//*[@id="container"]/div/div[1]/div[1]/div[2]/div[2]/form/div/div/input').send_keys(command); driver.find_element_by_xpath('/html/body/div[2]/div/div/button').click() search=driver.find_element_by_xpath('//*[@id="container"]/div/div[1]/div[1]/div[2]/div[2]/form/div/button/svg') search.click() #google search elif 'search' in command: command=command.replace('search','') pwk.search(command) #jokes using pyjokes library elif 'joke' in command: joke=pyjokes.get_jokes(language="en",) speak(joke[(random.randint(1, 5))]) #Weather updates using Weather_forecast library elif 'weather' in command: if 'in' in command: com=command.split('in',1) loc=com[1].capitalize() speak(wf.forecast(loc),time=dt.datetime.now().strftime('%X'),date=dt.datetime.now().strftime('%x')) else: speak('Please repeat the question with location') #News updates using GoogleNews library elif 'news' in command: ggn = GoogleNews('en') if 'about' in command: com=command.split('about',1) newz=com[1].capitalize() ggn.search(newz) ggn.getpage(1) print(ggn.gettext()) speak(ggn.gettext()) if 'on' in command: com=command.split('on',1) newz=com[1].capitalize() ggn.search(newz) ggn.getpage(1) print(ggn.gettext()) speak(ggn.gettext()) else: ggn.search('India') ggn.getpage(0) print(ggn.gettext()) speak(ggn.gettext()) else: pwk.search(command) except: pass