Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preliminary support for fetching more than 100 articles with dynamic date range adjustments #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

irenayli
Copy link

@irenayli irenayli commented Dec 9, 2024

For the highly-requested functionality to fetch more than 100 articles, this preliminary implementation uses a sliding time window to bypass Google's RSS feed limit of 100 per query.

If the user requests more than 100 max_results, a new helper function named _get_news_more_than_100() is called. After calling the first 100 results, this function re-queries Google's RSS feed, specifying the 7 days before the earliest published date seen so far as the time window. This allows new articles to be retrieved until max_results articles are fetched, or until the search is exhausted, whichever comes first.

This function currently works by resetting start_date and end_date to their default values. For this reason, fetching more than 100 articles is currently NOT compatible with a user-specified start_date, end_date, or period. If the user specifies any of these parameters, the function will raise a warning and reset start_date and end_date to None before proceeding.

I have added one test case testing this functionality by querying Google News for at most 150 articles, called test_get_news_more_than_100().

key = "%20".join(key.split(" "))
query = '/search?q={}'.format(key)
return self._get_news(query)

def _get_news_more_than_100(self, key):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @irenayli Thanks for the PR, can you please add some examples in readme ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants