def fetch_comment_op_thread(comment_op, comment_keys, username, only_authored): # Skip comments we've already fetched op_key = get_key(comment_op) if op_key in comment_keys: return [] post_comments = [] # We can't fetch deleted comments from the api, so try to use the parent # to fill in the information missing from the operation comment = fetch_comment(op_key) if comment_is_not_found(comment): parent_comment = fetch_comment(get_parent_key(comment_op)) if comment_is_not_found(parent_comment): print_with_timestamp('Could not find \'{}\', skipping...'.format(get_link_string(*op_key))) return [] post_comments.append(make_comment_from_parent(comment_op, parent_comment)) print_with_timestamp('Comment \'{}\' was deleted but was able to fill in information from parent'.format(get_link_string(*op_key))) comment = parent_comment # Now that the deleted comment was added, find the root comment from the parent if only_authored and comment['root_author'] != username: return [] # If this isn't the root comment, fetch it comment_key = get_key(comment) root_key = get_root_key(comment) root_comment = comment if root_key == comment_key else fetch_comment(root_key) with timer('Fetching post \'{}\''.format(get_link_string(*root_key))): post_comments.extend(fetch_thread(root_comment, comment_keys)) return post_comments
def display_thread(author, permlink): result = list(db.select(db.comment, dict(author=author, permlink=permlink))) if not result: print('Could not find thread \'{}\' in the database'.format( get_link_string(author, permlink))) return comment = result[0] root_author, root_permlink = get_root_key(comment) post_comments = list( db.select(db.comment, dict(root_author=root_author, root_permlink=root_permlink))) parent_groups = group_comments_by_parent(post_comments) comment_tree = build_comment_tree(comment, parent_groups) display_comment_tree(comment_tree)
def print_comment(c, depth): indent = ' ' * 4 * depth header_message = f'@{c["author"]}: {c["created"]}'[:-3] if c['was_deleted']: header_message += ' (deleted)' header = indent + get_header_string(header_message) body = indent + c['body'].replace('\n', '\n' + indent) + '\n\n' if depth == 0: if c['title']: print('\n' + colored( get_header_string(c['title']), 'green', attrs=['bold'])) print( colored(get_header_string(get_link_string(*get_key(c))) + '\n\n', 'green', attrs=['bold'])) print(colored(header, 'green')) print(body)
def archive_thread(author, permlink): with timer('Archive thread \'{}\''.format(get_link_string(author, permlink))): thread_comments = fetch.fetch_thread_rows(author, permlink) if thread_comments: insert_comments(thread_comments)
def fetch_thread_rows(author, permlink): comment = fetch_comment((author, permlink)) if comment_is_not_found(comment): print('Could not find thread \'{}\''.format(get_link_string(author, permlink))) return [] return format_comment_rows(fetch_thread(comment))