diff --git a/requirements.txt b/requirements.txt index d4e73e2..6291927 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,6 +28,8 @@ speechrecognition~=3.10.0 urllib3~=2.2.2 wheel~=0.41.2 wikipedia~=1.4.0 +feedparser~=6.0.11 +sgmllib3k~=1.0.0 # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/src/assistant.py b/src/assistant.py index b83f810..3099279 100755 --- a/src/assistant.py +++ b/src/assistant.py @@ -125,6 +125,9 @@ def execute_query(self, query: str) -> None: else: print("Scroll command not recognized") + elif "news" in query: + commands.fetch_news(self.__voice_interface) + else: self.__voice_interface.speak("could not interpret the query") diff --git a/src/commands.py b/src/commands.py index 8084f0c..69a9dc0 100644 --- a/src/commands.py +++ b/src/commands.py @@ -15,6 +15,7 @@ from datetime import datetime from subprocess import CalledProcessError, TimeoutExpired +import feedparser import googlesearch import pyautogui as pag import pygetwindow @@ -293,3 +294,26 @@ def simple_scroll(direction: str) -> None: pag.press(keys=direction, presses=25) else: print("Invalid direction") + + +def fetch_news(vi: VoiceInterface) -> None: + """News Reporter fetches headlines from news.google.com rss feed and reads top 5 headlines""" + + feed_url = "https://news.google.com/rss?hl=en-IN&gl=IN&ceid=IN:en" + max_fetched_headlines = 5 + + vi.speak("Fetching news from servers.") + + feed = feedparser.parse(feed_url) + if feed.status == 200: + headlines_list = [] + for entry in feed.entries[:max_fetched_headlines]: + headlines_list.append((entry.title).split(" -")[0]) + + vi.speak("Here are some recent news headlines.") + + for headline in headlines_list: + vi.speak(headline) + + else: + vi.speak("Failed to fetch the news.")