def _build_post(cls, op, date, pid=None): """Validate and normalize a post operation.""" # if this is a top-level post: if not op['parent_author']: parent_id = None depth = 0 category = op['parent_permlink'] community = cls._get_op_community(op, date) or op['author'] # this is a comment; inherit parent props. else: parent_id = cls.get_id(op['parent_author'], op['parent_permlink']) sql = "SELECT depth,category,community FROM hive_posts WHERE id=:id" parent_depth, category, community = DB.query_row(sql, id=parent_id) depth = parent_depth + 1 # check post validity in specified context is_valid = date < '2018-07-01' or is_community_post_valid(community, op) if not is_valid: url = "@%s/%s" % (op['author'], op['permlink']) log.info("Invalid post %s in @%s", url, community) return dict(author=op['author'], permlink=op['permlink'], id=pid, is_valid=is_valid, parent_id=parent_id, depth=depth, category=category, community=community, date=date)
def _build_post(cls, op, date, pid=None): # either a top-level post or comment (with inherited props) if not op['parent_author']: parent_id = None depth = 0 category = op['parent_permlink'] community = cls._get_op_community(op) or op['author'] else: parent_id = cls.get_id(op['parent_author'], op['parent_permlink']) sql = "SELECT depth,category,community FROM hive_posts WHERE id=:id" parent_depth, category, community = DB.query_row(sql, id=parent_id) depth = parent_depth + 1 # check post validity in specified context is_valid = is_community_post_valid(community, op) if not is_valid: url = "@{}/{}".format(op['author'], op['permlink']) print("Invalid post {} in @{}".format(url, community)) return dict(author=op['author'], permlink=op['permlink'], id=pid, is_valid=is_valid, parent_id=parent_id, depth=depth, category=category, community=community, date=date)