Skip to content

Commit e70f0a5

Browse files
committed
Fall back on showing summary if content is not available for an article
1 parent 1ed6e1a commit e70f0a5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

reader/feed.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
"""Interact with the Real Python feed"""
22
# Standard library imports
3-
from typing import List
3+
from typing import Dict, List
44

55
# Third party imports
66
import feedparser
77
import html2text
88

99
# Reader imports
1010
from reader import URL
11-
12-
_CACHED_FEED = feedparser.FeedParserDict()
11+
_CACHED_FEEDS: Dict[str, feedparser.FeedParserDict] = dict()
1312

1413

1514
def _feed() -> feedparser.FeedParserDict:
1615
"""Cache contents of the feed, so it's only read once"""
17-
if not _CACHED_FEED:
18-
_CACHED_FEED.update(feedparser.parse(URL))
19-
return _CACHED_FEED
16+
if URL not in _CACHED_FEEDS:
17+
_CACHED_FEEDS[URL] = feedparser.parse(URL)
18+
return _CACHED_FEEDS[URL]
2019

2120

2221
def get_site() -> str:
@@ -35,7 +34,10 @@ def get_article(article_id: str) -> str:
3534
msg = f"Unknown article ID, use ID from 0 to {max_id}"
3635
raise SystemExit(f"Error: {msg}")
3736

38-
html = article.content[0].value
37+
try:
38+
html = article.content[0].value
39+
except AttributeError:
40+
html = article.summary
3941
text = html2text.html2text(html)
4042
return f"# {article.title}\n\n{text}"
4143

0 commit comments

Comments
 (0)