From 772959054804568154301fa27e2ec24787b617ff Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 17 Dec 2019 12:42:38 -0800 Subject: [PATCH] Robustify inq feed to malformed items --- inquisitor/cli.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/inquisitor/cli.py b/inquisitor/cli.py index 7942440..2ce19f0 100644 --- a/inquisitor/cli.py +++ b/inquisitor/cli.py @@ -153,7 +153,8 @@ def command_feed(args): width = min(80, size.columns) for item in items: - titles = [item['title']] + title = item['title'] if 'title' in item else "" + titles = [title] while len(titles[-1]) > width - 4: i = titles[-1][:width - 4].rfind(' ') titles = titles[:-1] + [titles[-1][:i].strip(), titles[-1][i:].strip()] @@ -162,13 +163,14 @@ def command_feed(args): print("| {0:<{1}} |".format(title, width - 4)) print("|{0:<{1}}|".format("", width - 2)) info1 = "" - if item['author']: + if 'author' in title and item['author']: info1 += item['author'] + " " - if item['time']: + if 'time' in item and item['time']: info1 += timestamp.stamp_to_readable(item['time']) print("| {0:<{1}} |".format(info1, width - 4)) + created = timestamp.stamp_to_readable(item['created']) if 'created' in item else "" info2 = "{0} {1} {2}".format( - item['source'], item['id'], timestamp.stamp_to_readable(item['created'])) + item['source'], item['id'], created) print("| {0:<{1}} |".format(info2, width - 4)) print('+' + (width - 2) * '-' + '+') print()