Skip to content

Commit f4de766

Browse files
committed
feat: Keep using the cached feed when the feed is offline
Closes #4
1 parent 72164b9 commit f4de766

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

example/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "django-rss-filter"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
description = "Filter public RSS feeds, remove articles that contain certain keywords or categories."
55
authors = [
66
{name = "Kevin Renskers", email = "[email protected]"},

rssfilter/models.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.db import models
77
from django.urls import reverse
88
from django.utils import timezone
9+
from httpx import ConnectError, ConnectTimeout
910

1011
from . import USER_AGENT
1112
from .settings import RSS_FILTER_CACHE_SECONDS
@@ -61,9 +62,13 @@ def get_feed_body(self) -> str:
6162
if self.cache_date and self.cache_date > five_mins_ago:
6263
return self.feed_body
6364

64-
r = httpx.get(self.feed_url, follow_redirects=True, timeout=2, headers={"User-Agent": USER_AGENT})
65-
self.feed_body = r.text
66-
self.cache_date = timezone.now()
67-
self.save()
65+
try:
66+
r = httpx.get(self.feed_url, follow_redirects=True, timeout=2, headers={"User-Agent": USER_AGENT})
67+
self.feed_body = r.text
68+
self.cache_date = timezone.now()
69+
self.save()
70+
except (ConnectTimeout, ConnectError):
71+
# Do nothing, just return the cached version
72+
pass
6873

6974
return self.feed_body

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)