Exemple #1
0
def get_parent_post_id(post: Comment, subreddit: Subreddit) -> Submission:
    """
    Takes any given comment object and returns the object of the
    original post, no matter how far up the chain it is. This is
    a very time-intensive function because of how Reddit handles
    rate limiting and the fact that you can't just request the
    top parent -- you have to just loop your way to the top.

    :param post: comment object
    :param r: the instantiated reddit object
    :return: submission object of the top post.
    """
    if not post.is_root:
        parent = subreddit.comment(id=clean_id(post.parent_id))
        return get_parent_post_id(parent, subreddit)
    else:
        return subreddit.submission(id=clean_id(post.parent_id))