def fetch_reply(msg, session_id): response = detect_intent_from_text(msg, session_id) if response.intent.display_name == 'getNewsType': retStr = getNewsType(dict(response.parameters)) top, lang = retStr.split(",") if lang == "": lang = "english" if top == "": top = "Top Stories" if top == "Top Stories": print("Entered Top story") client = gnewsclient.NewsClient(language=lang, location="India", topic=top) res = client.get_news() newsStr = "" if len(res) == 0: newsStr += "Sorry!! No news to fetch!" else: for i in range(2): finalStr = "\n *" + res[i][ 'title'] + "*" + "\n\n" + "*Link to be followed* \n" + res[ i]['link'] + "\n\n" newsStr += finalStr return newsStr else: print("Entered else") client = gnewsclient.NewsClient(language=lang, location="India", topic=top, max_results=5) res = client.get_news() newsStr = "" for i in range(len(res)): finalStr = "\n *" + res[i][ 'title'] + "*" + "\n\n" + "*Link to be followed* \n" + res[ i]['link'] + "\n\n" newsStr += finalStr return newsStr elif response.intent.display_name == 'workDone': print("Entered WorkDone!") retStr = "Hi!\n" + "I am your personal NewsBot!\n" + "I can get you news on various topics as listed below:\n\n" + "1.)World\n2.)Nation\n3.)Business\n4.)Entertainment\n5.)Health\n6.)Science and more.." return retStr else: return response.fulfillment_text
def runGClient(self, topic): client = gnewsclient.NewsClient( language="english", location="United States", topic=f"{topic}", max_results=10, ) return client.get_news()
def news(topic): client = gnewsclient.NewsClient(language='english', location='india', topic=topic, max_results=3) n = [i['title'] for i in client.get_news()] for i in n: speak(i)
def news(request): from gnewsclient import gnewsclient cli = gnewsclient.NewsClient(language='english', location='India', topic='Tourism in India', max_results=10) dict = {'news_list': cli.get_news(), 'cli': cli} return render(request, 'CPSapp/news.html', dict)
def news(): try: client = gnewsclient.NewsClient(language="english", location="india", topic="business", max_results=3) news_list = client.get_news() return (news_list[0]["title"] + "\n" + news_list[1]["title"] + "\n" + news_list[2]["title"]) except: return "unable to fetch the news"
def fetch_news(parameters): print(parameters) client = gnewsclient.NewsClient() country = parameters.get('geo-country') if country == '': country = "India" client.language = parameters.get('language') client.location = country client.topic = parameters.get('news') return client.get_news()[:5]
def get(self,request,house,name): client = gnewsclient.NewsClient(language='english', location='india', topic=name, max_results=3) news = {} news = (client.get_news()) getValues = lambda key,inputData: [subVal[key] for subVal in inputData if key in subVal] g_news_title = getValues('title', news) g_news_links = getValues('link', news) candidate_obj = Candidate.objects.get(name=name) centrail_leg_id = Central_Legislatures.objects.get(name=house) candidature_obj = Candidature.objects.filter(candidate_id=candidate_obj) attendance = Attendance.objects.filter(candidate_id=candidate_obj) return render(request,self.template_name, {'members':candidature_obj[0],'attendance':attendance,'house':house, 'g_news_title':g_news_title,'g_news_links':g_news_links})
def index(request): lan = "hindi" client = gnewsclient.NewsClient(language=lan, location='india', topic='agriculture', max_results=3) news_list = client.get_news() item1 = news_list[0] item2 = news_list[2] item3 = news_list[2] paramas = { "news1": item1['title'], "news2": item2['title'], "news3": item3['title'] } return render(request, 'assume/index.html', paramas)
def news(): window2 = Toplevel() window2.title("NEWS List") client = gnewsclient.NewsClient(language=lang.get(), location=loc.get(), topic=top.get(), max_results=5) news_list = client.get_news() result_title_1.set(news_list[0]["title"]) result_title_2.set(news_list[1]["title"]) result_title_3.set(news_list[2]["title"]) result_title_4.set(news_list[3]["title"]) result_title_5.set(news_list[4]["title"]) link1 = Label(window2, textvariable=result_title_1, foreground="blue", cursor="hand2") link2 = Label(window2, textvariable=result_title_2, foreground="blue", cursor="hand2") link3 = Label(window2, textvariable=result_title_3, foreground="blue", cursor="hand2") link4 = Label(window2, textvariable=result_title_4, foreground="blue", cursor="hand2") link5 = Label(window2, textvariable=result_title_5, foreground="blue", cursor="hand2") link1.grid(row=0, column=1) link2.grid(row=1, column=1) link3.grid(row=2, column=1) link4.grid(row=3, column=1) link5.grid(row=4, column=1) link1.bind("<Button-1>", lambda event: Open(str(news_list[0]["link"]), 1)) link2.bind("<Button-1>", lambda event: Open(str(news_list[1]["link"]), 2)) link3.bind("<Button-1>", lambda event: Open(str(news_list[2]["link"]), 3)) link4.bind("<Button-1>", lambda event: Open(str(news_list[3]["link"]), 4)) link5.bind("<Button-1>", lambda event: Open(str(news_list[4]["link"]), 5))
def get_news_elements(categories): news_client = gnewsclient.NewsClient() news_client.topic = '' if 'news_type' in categories.keys(): news_client.topic+=categories['news_type']+' ' if 'location' in categories.keys(): news_client.topic+=categories['location'] news_items = news_client.get_news() elements = [] for item in news_items: element = {'title':item['title'], 'buttons':[{ 'type':'web_url', 'title':'Read More', 'url':item['link'] }], 'image_url':item['img'] } elements.append(element) return elements
import os from gnewsclient import gnewsclient os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "client-secret.json" import dialogflow_v2 as dialogflow dialogflow_session_client = dialogflow.SessionsClient() PROJECT_ID = "newsbot-npspvj" client = gnewsclient.NewsClient(max_results=3) def get_news(parameters): client.topic = parameters.get('news_type') client.language = parameters.get('language') client.location = parameters.get('geo-country') return client.get_news() def detect_intent_from_text(text, session_id, language_code='en'): session = dialogflow_session_client.session_path(PROJECT_ID, session_id) text_input = dialogflow.types.TextInput(text=text, language_code=language_code) query_input = dialogflow.types.QueryInput(text=text_input) response = dialogflow_session_client.detect_intent(session=session, query_input=query_input) return response.query_result
import os os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "client.json" import dialogflow_v2 as dialogflow dialogflow_session_client=dialogflow.SessionsClient() Project_id = "arkarebot-cgeent" from gnewsclient import gnewsclient client = gnewsclient.NewsClient() def detect_intent_from_text(text,session_id,language_code='en'): session = dialogflow_session_client.session_path(Project_id,session_id) text_input = dialogflow.types.TextInput(text=text, language_code=language_code) query_input = dialogflow.types.QueryInput(text=text_input) response = dialogflow_session_client.detect_intent(session=session, query_input=query_input) return response.query_result def get_reply(query,chat_id): response = detect_intent_from_text(query,chat_id) if response.intent.display_name == 'get_news': return "get_news",dict(response.parameters) else: return "small_talk", response.fulfillment_text def fetch_news(parameters): client.language = parameters.get('language') client.location = parameters.get('geo-country') client.topic = parameters.get('topic') return client.get_news()[:5] topics_keyboard = [
try: googlenews.search(keywordToSearch) gnews = googlenews.result() gnewsDataFrame = pd.DataFrame(gnews) # gnewsDataFrame=gnewsDF.drop(['link', 'media', 'date'], axis=1) data = gnewsDataFrame.head(4) data.reset_index(inplace=True) data_dict = data.to_dict("records") GoogleNewsSearchKeywordCollection.insert_many(data_dict) except: print("Error in specific category for News") try: user_topic = user_category client = gnewsclient.NewsClient(language='english', location='', topic=user_topic, max_results=4) df = pd.DataFrame(client.get_news()) x = df.drop(['link', 'media'], axis=1) data = x NewsCateogoryNews = data data.reset_index(inplace=True) data_dict = data.to_dict("records") GoogleNewsCategoryCollection.insert_many(data_dict) except: print("No Goolge News") # connect to Mongo DB Server # client = MongoClient("mongodb://*****:*****@sdgp1-fmfys.mongodb.net/test?retryWrites=true&w=majority") #atlas
speak('An error occured.') break # Check for the keyword in query elif 'tell me a quote' in query: # Get a random quote quote = tellQuote() print(quote) speak(quote) exit() # Ckeck the keyword in query elif 'current news' in query: # Get Current news using the Google News Client module available in python client = gnewsclient.NewsClient(language='english', max_results=5) # Extract the top 5 news in english language for item in client.get_news(): # Printa and says the title of the news and also mentions the link to the article print("Title: " + item['title']) speak(item['title']) print() print("Link: " + item['link']) print() exit() # Ckeck the keyword in query elif 'write a note' in query: # Creates a text file which will be like a todo list