From 0c29ac65420b8d43f2f42c701ec00de774a1b1ba Mon Sep 17 00:00:00 2001 From: Umesh Singh <83420185+Umesh-01@users.noreply.github.com> Date: Mon, 17 May 2021 15:09:01 +0530 Subject: [PATCH] added a feature to get the latest news headlines fetching the data from google news --- PA.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PA.py b/PA.py index 5aa9f50..a3b93d7 100644 --- a/PA.py +++ b/PA.py @@ -664,3 +664,22 @@ def send_whtmsg(): fun_talk(data[0].summary) except Exception as e: fun_talk('Sorry, I am unable to find the answer for your query.') + + elif 'news' in query or 'news headlines' in query: + url = "https://news.google.com/news/rss" + client = urlopen(url) + xml_page = client.read() + client.close() + page = bs4.BeautifulSoup(xml_page, 'xml') + news_list = page.findAll("item") + fun_talk("Today's top headlines are--") + try: + for news in news_list: + print(news.title.text) + # print(news.pubDate.text) + fun_talk(f"{news.title.text}") + # fun_talk(f"{news.pubDate.text}") + print() + + except Exception as e: + pass