File tree Expand file tree Collapse file tree 3 files changed +51
-3
lines changed
Expand file tree Collapse file tree 3 files changed +51
-3
lines changed Original file line number Diff line number Diff line change 1+ """Read the latest Real Python tutorials
2+
3+ Usage:
4+ ------
5+
6+ List the latest tutorials:
7+
8+ $ realpython
9+
10+ Read one tutorial:
11+
12+ $ realpython <id>
13+
14+ where <id> is the number shown when listing tutorials.
15+
16+ Read the latest tutorial:
17+
18+ $ realpython 0
19+
20+
21+ Contact:
22+ --------
23+
24+ - https://realpython.com/contact/
25+
26+ More information is available at:
27+
28+ - https://pypi.org/project/realpython-reader/
29+ - https://github.com/realpython/reader
30+ """
31+ # Standard library imports
132import sys
233
34+ # Reader imports
335from reader import feed
436from reader import viewer
537
638
739def main () -> None :
840 """Read the Real Python article feed"""
41+ # Show help message
42+ if "-h" in sys .argv or "--help" in sys .argv :
43+ viewer .show (__doc__ )
44+ return
45+
946 # An article ID is given, show article
1047 if len (sys .argv ) > 1 :
1148 article = feed .get_article (sys .argv [1 ])
Original file line number Diff line number Diff line change 1+ """Interact with the Real Python feed"""
2+ # Standard library imports
13from typing import List
4+
5+ # Third party imports
26import feedparser
37import html2text
4- import reader
8+
9+ # Reader imports
10+ from reader import URL
511
612_CACHED_FEED = feedparser .FeedParserDict ()
713
814
915def _feed () -> feedparser .FeedParserDict :
1016 """Cache contents of the feed, so it's only read once"""
1117 if not _CACHED_FEED :
12- _CACHED_FEED .update (feedparser .parse (reader . URL ))
18+ _CACHED_FEED .update (feedparser .parse (URL ))
1319 return _CACHED_FEED
1420
1521
@@ -25,7 +31,9 @@ def get_article(article_id: str) -> str:
2531 try :
2632 article = articles [int (article_id )]
2733 except (IndexError , ValueError ):
28- raise SystemExit ("Error: Unknown article ID" )
34+ max_id = len (articles ) - 1
35+ msg = f"Unknown article ID, use ID from 0 to { max_id } "
36+ raise SystemExit (f"Error: { msg } " )
2937
3038 html = article .content [0 ].value
3139 text = html2text .html2text (html )
Original file line number Diff line number Diff line change 1+ """Functions for displaying the Real Python feed"""
2+
3+ # Standard library imports
14from typing import List
25
36
You can’t perform that action at this time.
0 commit comments