Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Changelog
=========

2.1.1 (unreleased)
2.2.0 (unreleased)
------------------

- Nothing changed yet.
- Allow configuring the User-Agent for the requests to get feeds,
via the REQUESTS_USER_AGENT environment variable.
[davisagli]


2.1.0 (2023-03-10)
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ There is a 5s default timeout for retrieve RSS feeds.

You can override it with an environment variable: **RSS_SERVICE_TIMEOUT**

Set User-Agent
--------------

You can override the default ``User-Agent`` for the requests to get feeds by setting an environment variable: **RSS_USER_AGENT**

Installation
============

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="redturtle.rssservice",
version="2.1.1.dev0",
version="2.2.0.dev0",
description="An add-on for Plone",
long_description=long_description,
# Get more from https://pypi.org/classifiers/
Expand Down
10 changes: 9 additions & 1 deletion src/redturtle/rssservice/rss_mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
FEED_DATA = {} # url: ({date, title, url, itemlist})

REQUESTS_TIMEOUT = int(environ.get("RSS_SERVICE_TIMEOUT", "5")) or 5
REQUESTS_USER_AGENT = environ.get("RSS_USER_AGENT")


class RSSMixerService(Service):
Expand Down Expand Up @@ -226,8 +227,15 @@ def _getFeedFromUrl(self, url):
Use urllib to retrieve an rss feed.
In this way, we can manage timeouts.
"""
headers = {}
if REQUESTS_USER_AGENT:
headers["User-Agent"] = REQUESTS_USER_AGENT
try:
response = requests.get(url, timeout=REQUESTS_TIMEOUT)
response = requests.get(
url,
headers=headers,
timeout=REQUESTS_TIMEOUT,
)
except (Timeout, RequestException) as e:
logger.exception(e)
return None
Expand Down