Exemplo n.º 1
0
def addToDatabase(parent, subtree, i):

    subComments = subtree["data"]["children"]
    if len(subComments) == 0:
        pass
        # print "List EMPTY"
    w = 0
    for j in subComments:
        comment = Comment()
        comment.reddit_id = j["data"]["id"]
        comment.text = j["data"]["body"]
        comment.user_name = j["data"]["author"]
        comment.upvotes = int(j["data"]["ups"])
        comment.downvotes = j["data"]["downs"]
        comment.date_of_last_sweep = datetime.now()
        comment.parent = parent
        comment.post_id = parent.post_id
        session.add(comment)
        if j["data"]["replies"] == "":
            comment.weight = comment.upvotes
            # print "Dict Empty"
            # print type(j["data"]["replies"])

        else:
            addToDatabase(comment, j["data"]["replies"], i + 1)
            comment.weight = comment.weight + comment.upvotes
        w = comment.weight + w
    parent.weight = w

    """