Exemplo n.º 1
0
def main():
	"""Download and print the latest tutorial from Real Python"""
	tic = time.perf_counter()    
	tutorial = feed.get_article(0)
	toc = time.perf_counter()
	print(f"Downloaded the tutorial in {toc - tic:0.4f} seconds")
	print(tutorial)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def test_article_title(local_feed):
    """Test that title is added at top of article"""
    article_id = 0
    title = feed.get_titles(url=local_feed)[article_id]
    article = feed.get_article(article_id, url=local_feed)

    assert article.strip("# ").startswith(title)
Exemplo n.º 4
0
def main():
    """Print the latest tutorial from Real Python"""
    t = Timer()
    t.start()
    tutorial = feed.get_article(0)
    t.stop()

    print(tutorial)
Exemplo n.º 5
0
def main():
    t = Timer("download", logger=None)
    for tutorial_num in range(10):
        t.start()
        tutorial = feed.get_article(tutorial_num)
        t.stop()
        print(tutorial)

    download_time = Timer.timers["download"]
    print(f"Downloaded 10 tutorials in {download_time:0.2f} seconds")
Exemplo n.º 6
0
def test_summary(local_summary_feed):
    """Test that summary feeds can be read"""
    article_id = 1
    summary_phrases = [
        "Get the inside scoop",
        "this list of\ninformative videos",
    ]
    summary = feed.get_article(article_id, url=local_summary_feed)

    for phrase in summary_phrases:
        assert phrase in summary
Exemplo n.º 7
0
def test_article(local_feed):
    """Test that article is returned"""
    article_id = 2
    article_phrases = [
        "logging.info('This is an info message')",
        "By using the `level` parameter",
        "  * `level`: The root logger",
    ]
    article = feed.get_article(article_id, url=local_feed)

    for phrase in article_phrases:
        assert phrase in article
Exemplo n.º 8
0
def main():
    """download the latest tutorial from RP"""
    #tic = time.perf_counter() # start counter
    t.start() 


    tutorial = feed.get_article(0)
    #toc = time.perf_counter() # stop timing
    t.stop()

    
    print()
    print()
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def main():
    tutorial = feed.get_article(1)
    print(tutorial)
Exemplo n.º 13
0
def main():
    """Download and print the latest tutorial from Real Python"""
    tutorial = feed.get_article(0)
    print(tutorial)
Exemplo n.º 14
0
# headlines.py

import parse
from reader import feed

tutorial = feed.get_article(0)
headlines = [
    r.named["header"] for r in parse.findall("\n## {header}\n", tutorial)
]
print("\n".join(headlines))
print("Okay that didnt work?")
Exemplo n.º 15
0
def main():
    """Download and print the latest tutorial from RP"""
    feed.get_article(0)
Exemplo n.º 16
0
def fetch_tutorial(tutorial_index):
    ''' Download and print the latest tutorial from Real Python '''
    tutorial = feed.get_article(tutorial_index)
    return tutorial
Exemplo n.º 17
0
def test_invalid_article_id(local_feed):
    """Test that invalid article ids are handled gracefully"""
    article_id = "wrong"
    with pytest.raises(SystemExit):
        feed.get_article(article_id, url=local_feed)