def get_news ():
    """Create an interactive user prompt to get the feed name
    or url to fetch and display"""

    option_prompt = '\t--- more --- [enter to continue, or # to read] '
    no_content = 'Sorry, there is no content at'

    while True:
        feed = prompt_user("Which feed do you want to read? Input code (! for menu, [enter] to quit) ")
        if len(feed) == 0:
            break
        elif "!" == feed:
            show_feed_menu()
        else:
            feed_referrer = None
            try:
                feed_data = interests[feed.lower()]
                feed_url  = feed_data['url']
                strip_parameters = True
                if feed_data.has_key('strip_url_parameters'):
                    strip_parameters = feed_data['strip_url_parameters']
                if feed_data.has_key('referrer'):
                    feed_referrer = feed_data['referrer']
                menu, links = get_items (feed_url, strip_parameters)
            except KeyError:
                # try interpreting the stdin typed by the user as a url
                menu, links = get_items(feed)

            if len(links) == 0:
                print no_content, feed
                break
            else:
                options = links.keys()
                bad_option = "Please choose between (%d-%d)" % (min(options),
                                                                max(options))

                def _display_article (user_choice):
                    """An inner function which captures the current feed 
                    links in a closure, and fetches the user-chosen link
                    for display using scroll_article()"""

                    break_menu = False

                    try:
                        choice = int(user_choice)
                        if choice in options:
                            article = get_article(links[choice], feed_referrer)
                            if article is not None:
                                scroll_output(article)
                                break_menu = True
                            else:
                                print no_content, links[choice]
                        else:
                            print bad_option
                    except ValueError:
                        pass

                    return break_menu

                scroll_output(menu,
                              wrap_data=False,
                              prompt=option_prompt,
                              choice_fn=_display_article)

                while True:
                    choice = prompt_user(
                        "Which article do you want to see? "\
                        "(%d-%d, or [enter] for none) "
                        % (min(options), max(options)))
                    if 0 == len(choice):
                        break
                    if _display_article(choice):
                        break
dataset/ETHPy150Open dpapathanasiou/cmdline-news/cmdlinenews.py/get_news/original