File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 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
66import feedparser
77import html2text
88
99# Reader imports
1010from reader import URL
11-
12- _CACHED_FEED = feedparser .FeedParserDict ()
11+ _CACHED_FEEDS : Dict [str , feedparser .FeedParserDict ] = dict ()
1312
1413
1514def _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
2221def 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
You can’t perform that action at this time.
0 commit comments