realpython-reader-practice-module-test 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
reader/__init__.py ADDED
@@ -0,0 +1,14 @@
1
+ #__init__.py
2
+
3
+ from importlib import resources
4
+
5
+ try:
6
+ import tomllib
7
+ except ModuleNotFoundError:
8
+ import tomllib as tomllib
9
+
10
+ __version__ = "1.0.0"
11
+
12
+ _cfg = tomllib.loads(resources.read_text("reader","config.toml"))
13
+ URL = _cfg["feed"]["url"]
14
+ LIMIT = _cfg["feed"].get("limit",20)
reader/__main__.py ADDED
@@ -0,0 +1,22 @@
1
+ # __main__.py
2
+
3
+ import sys
4
+
5
+ from reader import feed, viewer
6
+
7
+ def main():
8
+ """Read the Real Python article feed"""
9
+
10
+ #If an article ID is given, then show the article
11
+ if len(sys.argv) > 1:
12
+ article = feed.get_article(sys.argv[1])
13
+ viewer.show(article)
14
+
15
+ # If no ID is given, then show a list of all articles
16
+ else:
17
+ site = feed.get_site()
18
+ titles = feed.get_titles()
19
+ viewer.show_list(site, titles)
20
+
21
+ if __name__ == "__main__":
22
+ main()
reader/feed.py ADDED
@@ -0,0 +1,29 @@
1
+ from functools import cache
2
+
3
+ import feedparser
4
+ try:
5
+ import html2text
6
+ except ImportError:
7
+ raise ImportError("The 'html2text' library is required. Install it using 'pip install html2text'.")
8
+
9
+ import reader
10
+
11
+ @cache
12
+ def _get_feed(url=reader.URL):
13
+ return feedparser.parse(url)
14
+
15
+ def get_site(url=reader.URL):
16
+ feed = _get_feed(url).feed
17
+ return f"{feed.title} ({feed.link})"
18
+
19
+ def get_titles(url=reader.URL):
20
+ articles = _get_feed(url).entries
21
+ return [a.title for a in articles]
22
+
23
+ def get_article(article_id, url=reader.URL):
24
+ articles = _get_feed(url).entries
25
+ article = articles[int(article_id)]
26
+ html = article.content[0].value
27
+ text = html2text.html2text(html)
28
+ return f"# {article.title}\n\n{text}"
29
+
reader/viewer.py ADDED
@@ -0,0 +1,9 @@
1
+ def show(article):
2
+ print(article)
3
+
4
+ def show_list(site, titles):
5
+ print(f"The latest tutorial from {site}")
6
+ for article_id, title in enumerate(titles):
7
+ print(f"{article_id:>3} {title}")
8
+
9
+
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: realpython-reader-practice-module-test
3
+ Version: 1.0.0
4
+ Summary: Module for read feed TEST Practice Module
5
+ Requires-Python: >=3.11
6
+ License-File: LICENSE
7
+ Requires-Dist: feedparser
8
+ Requires-Dist: html2text
9
+ Requires-Dist: tomli; python_version < "3.11"
10
+ Dynamic: license-file
@@ -0,0 +1,10 @@
1
+ reader/__init__.py,sha256=y4ZjoxBbNGT8OIrusK6B7gvS7VJDoooA1rlI5Wrm314,296
2
+ reader/__main__.py,sha256=gPlZvvV4pqVDH4q1J4sZCuVJjgprKZFuUhJCIYqaYb8,519
3
+ reader/feed.py,sha256=jKy9WPiWX9AwVqGiqzo7qpO0AJg1s7c_fnuKIXVP1hs,767
4
+ reader/viewer.py,sha256=U1f0k4RbTf2Z9o7ZhTU1mQiaKFVz1KhDMqNCzrC7XYo,229
5
+ realpython_reader_practice_module_test-1.0.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ realpython_reader_practice_module_test-1.0.0.dist-info/METADATA,sha256=5bo5EwvZYwaLXoG346JFoWfTqhvfkD6qtkavtyzAAIc,308
7
+ realpython_reader_practice_module_test-1.0.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
8
+ realpython_reader_practice_module_test-1.0.0.dist-info/entry_points.txt,sha256=j4KgHXbVGbGyfTySc1ypBdERpfihO4WNjppvCdE9HjE,52
9
+ realpython_reader_practice_module_test-1.0.0.dist-info/top_level.txt,sha256=zVRv6FulXZWKf9Gycz9vjxul5OCZ3fCq2Attdwsu7Z4,7
10
+ realpython_reader_practice_module_test-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ realpython = reader.__main__:main