11"""Interact with the Real Python feed"""
22# Standard library imports
3- from typing import Dict , List
3+ from typing import Dict , List # noqa
44
55# Third party imports
66import feedparser
77import html2text
88
99# Reader imports
1010from reader import URL
11- _CACHED_FEEDS : Dict [str , feedparser .FeedParserDict ] = dict ()
1211
12+ _CACHED_FEEDS = dict () # type: Dict[str, feedparser.FeedParserDict]
1313
14- def _feed () -> feedparser .FeedParserDict :
14+
15+ def _feed (): # type: () -> feedparser.FeedParserDict
1516 """Cache contents of the feed, so it's only read once"""
1617 if URL not in _CACHED_FEEDS :
1718 _CACHED_FEEDS [URL ] = feedparser .parse (URL )
1819 return _CACHED_FEEDS [URL ]
1920
2021
21- def get_site () -> str :
22+ def get_site (): # type: () -> str
2223 """Get name and link to web site of the feed"""
2324 info = _feed ().feed
24- return f "{ info .title } ({ info .link } )"
25+ return "{info.title} ({info.link})" . format ( info = info )
2526
2627
27- def get_article (article_id : str , links : bool = False ) -> str :
28+ def get_article (article_id , links = False ): # type: (str, bool ) -> str
2829 """Get article from feed with the given ID"""
2930 articles = _feed ().entries
3031 try :
3132 article = articles [int (article_id )]
3233 except (IndexError , ValueError ):
3334 max_id = len (articles ) - 1
34- msg = f "Unknown article ID, use ID from 0 to { max_id } "
35- raise SystemExit (f "Error: { msg } " )
35+ msg = "Unknown article ID, use ID from 0 to {}" . format ( max_id )
36+ raise SystemExit ("Error: {}" . format ( msg ) )
3637
3738 # Get article as HTML
3839 try :
@@ -45,10 +46,10 @@ def get_article(article_id: str, links: bool = False) -> str:
4546 to_text .ignore_links = not links
4647 text = to_text .handle (html )
4748
48- return f "# { article . title } \n \n { text } "
49+ return u "# {}\n \n {}" . format ( article . title , text )
4950
5051
51- def get_titles () -> List [str ]:
52+ def get_titles (): # type: () -> List[str]
5253 """List titles in feed"""
5354 articles = _feed ().entries
5455 return [a .title for a in articles ]
0 commit comments