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 1
1
"""Interact with the Real Python feed"""
2
2
# Standard library imports
3
- from typing import List
3
+ from typing import Dict , List
4
4
5
5
# Third party imports
6
6
import feedparser
7
7
import html2text
8
8
9
9
# Reader imports
10
10
from reader import URL
11
-
12
- _CACHED_FEED = feedparser .FeedParserDict ()
11
+ _CACHED_FEEDS : Dict [str , feedparser .FeedParserDict ] = dict ()
13
12
14
13
15
14
def _feed () -> feedparser .FeedParserDict :
16
15
"""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 ]
20
19
21
20
22
21
def get_site () -> str :
@@ -35,7 +34,10 @@ def get_article(article_id: str) -> str:
35
34
msg = f"Unknown article ID, use ID from 0 to { max_id } "
36
35
raise SystemExit (f"Error: { msg } " )
37
36
38
- html = article .content [0 ].value
37
+ try :
38
+ html = article .content [0 ].value
39
+ except AttributeError :
40
+ html = article .summary
39
41
text = html2text .html2text (html )
40
42
return f"# { article .title } \n \n { text } "
41
43
You can’t perform that action at this time.
0 commit comments