Esempio n. 1
0
def list_cmd(feed):
    """ Run the list command. Print out a list of recent news item titles. """
    argv = InformantConfig().get_argv()
    if argv.get(REV_OPT):
        feed_list = reversed(feed)
    else:
        feed_list = feed
    index = 0
    for entry in feed_list:
        if not argv.get(UNREAD_OPT) \
        or (argv.get(UNREAD_OPT) and not entry.has_been_read()):
            print(ui.format_list_item(entry, index))
            index += 1
Esempio n. 2
0
def read_cmd(feed):
    """ Run the read command. Print news items and mark them as read. """
    argv = InformantConfig().get_argv()
    if argv.get(READALL_OPT):
        for entry in feed:
            entry.mark_as_read()
    else:
        if argv[ITEM_ARG]:
            try:
                item = int(argv[ITEM_ARG])
                entry = feed[item]
            except ValueError:
                for entry in feed:
                    if entry.title == item:
                        break
                #NOTE: this will read the oldest unread item if no matches are found
            ui.pretty_print_item(entry)
            entry.mark_as_read()
        else:
            unread_entries = list()
            for entry in feed:
                if not entry.has_been_read():
                    unread_entries.insert(0, entry)
            for entry in unread_entries:
                ui.pretty_print_item(entry)
                entry.mark_as_read()
                if entry is not unread_entries[-1]:
                    read_next = ui.prompt_yes_no('Read next item?', 'yes')
                    if read_next in ('n', 'no'):
                        break
                else:
                    print('No more unread items')
    fs.save_datfile()
Esempio n. 3
0
def run():
    """ The main function.
    Check given arguments get feed and run given command. """
    argv = InformantConfig().get_argv()
    config = InformantConfig().get_config()
    if argv.get(DEBUG_OPT):
        ui.debug_print('cli args: {}'.format(argv))

    if 'feeds' in config:
        feed = []
        for config_feed in config['feeds']:
            feed += Feed(config_feed).entries
    else:
        feed = Feed().entries

    feed = sorted(feed, key=lambda k: k.timestamp, reverse=True)

    if argv.get(CHECK_CMD):
        check_cmd(feed)
    elif argv.get(LIST_CMD):
        list_cmd(feed)
    elif argv.get(READ_CMD):
        read_cmd(feed)
Esempio n. 4
0
def pretty_print_item(entry):
    """ Print out the given entry, replacing some markup to make it look nicer.
    If the '--raw' option has been provided then the markup will not be
    replaced. """
    argv = InformantConfig().get_argv()
    title = entry.title
    body = entry.body
    bold = InformantConfig().colors['BOLD']
    clear = InformantConfig().colors['CLEAR']
    timestamp = str(entry.pretty_date)
    if not argv.get(RAW_OPT):
        #if not using raw also bold title
        title = bold + title + clear
        h2t = html2text.HTML2Text()
        h2t.inline_links = False
        h2t.body_width = 85
        body = h2t.handle(body)
    if entry.feed_name is not None:
        feed_name = '({})'.format(entry.feed_name)
        print('{}\n{}\n{}\n\n{}'.format(title, feed_name, timestamp, body))
    else:
        print('{}\n{}\n\n{}'.format(title, timestamp, body))