Example #1
0
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)
Example #2
0
def main():
    args = [a for a in sys.argv[1:] if not a.startswith("-")]

    url = reader.URL

    if args:
        for article_id in args:
            article = feed.get_article(article_id, url=url)
            viewer.show(article)
    else:
        site = feed.get_site(url=url)
        titles = feed.get_titles(url=url)
        viewer.show_list(site, titles)
def test_show_list(capsys):
    """Test that show_list shows a list of items with an ID"""
    site = "Real Python"
    things = ["pathlib", "data classes", "python 3.7", "decorators"]
    viewer.show_list(site, things)
    stdout, stderr = capsys.readouterr()
    assert stderr == ""

    # Site name is shown in header
    lines = stdout.split("\n")
    assert site in lines[0]

    # Each thing is listed preceded by a number
    for thing, line in zip(things, lines[1:]):
        line_parts = line.split()
        assert line_parts[0].isnumeric()
        assert thing in line
Example #4
0
def main():
    """Read the Real Python article feed"""
    # Read URL of the Real Python feed from config file
    cfg = ConfigParser()
    cfg.read_string(resources.read_text("reader", "config.txt"))
    url = cfg.get("feed", "url")

    # If an article ID is given, show the article
    if len(sys.argv) > 1:
        article = feed.get_article(url, sys.argv[1])
        viewer.show(article)

    # If no ID is given, show a list of all articles
    else:
        site = feed.get_site(url)
        titles = feed.get_titles(url)
        viewer.show_list(site, titles)
Example #5
0
def main():
    """Read the RealPython article feed"""

    # Read url of the RealPython feed from the config file
    cfg = ConfigParser()  # initialize the ConfigParser
    # resources.read_text(package, resource, encoding, errors)
    cfg.read_string(resources.read_text("reader", "config.txt"))
    url = cfg.get("feed", "url")

    # If an article id is given, show the article
    if len(sys.argv) > 1:
        article = feed.get_article(url, sys.argv[1])
        viewer.show(article)

    # If no id is given, so the list of all articles
    else:
        site = feed.get_site(url)
        titles = feed.get_titles(url)
        viewer.show_list(site, titles)