forked from realpython/reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
84 lines (54 loc) · 1.58 KB
/
__main__.py
File metadata and controls
84 lines (54 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Read the latest Real Python tutorials
Usage:
------
$ realpython [options] [id] [id ...]
List the latest tutorials:
$ realpython
Read one tutorial:
$ realpython <id>
where <id> is the number shown when listing tutorials.
Read the latest tutorial:
$ realpython 0
Available options are:
-h, --help Show this help
-l, --show-links Show links in text
Contact:
--------
- https://realpython.com/contact/
More information is available at:
- https://pypi.org/project/realpython-reader/
- https://github.com/realpython/reader
Version:
--------
- realpython-reader v1.0.0
"""
# Standard library imports
import sys
# Reader imports
import reader
from reader import feed
from reader import viewer
def main(): # type: () -> None
"""Read the Real Python article feed"""
args = [a for a in sys.argv[1:] if not a.startswith("-")]
opts = [o for o in sys.argv[1:] if o.startswith("-")]
# Show help message
if "-h" in opts or "--help" in opts:
viewer.show(__doc__)
return
# Should links be shown in the text
show_links = "-l" in opts or "--show-links" in opts
# Get URL from config file
url = reader.URL
# An article ID is given, show article
if args:
for article_id in args:
article = feed.get_article(article_id, links=show_links, url=url)
viewer.show(article)
# No ID is given, show list of articles
else:
site = feed.get_site(url=url)
titles = feed.get_titles(url=url)
viewer.show_list(site, titles)
if __name__ == "__main__":
main()