Example #1
0
def add_comment(contribution):
    """Adds the authorperm of the moderator's comment to the database."""
    if contribution.moderator == "amosbastian":
        return

    post = Comment(contribution.url)

    inserted = False
    for comment in post.get_replies():
        if comment.author == contribution.moderator:
            age = comment.time_elapsed()
            collection = constants.DB.comments
            collection.insert({
                "url":
                comment.authorperm,
                "upvote_time":
                datetime.now() + timedelta(minutes=10) - age,
                "inserted":
                datetime.now(),
                "upvoted":
                False,
                "category":
                contribution.category
            })
            inserted = True

    if not inserted:
        collection = constants.DB.missed_posts
        collection.insert({
            "url": contribution.url,
            "moderator": contribution.moderator,
            "category": contribution.category
        })
Example #2
0
def post_detail(request, author, permlink, **args):
    author_perm = construct_authorperm(author, permlink)
    post = Comment(author_perm, blockchain_instance=hv)
    if post:
        replies = post.get_replies(raw_data=True)
        post = strip(post)
        for reply in replies:
            reply = strip(reply)
    return render(request, 'blog/post_detail.html', {'post': post, 'replies': replies})
Example #3
0
def rand_com(permalink):
    permlink = permalink.split("@")
    c = Comment(permlink[1])
    comments = c.get_replies()
    unique_authors = []
    unique_com = []
    for com in comments:
        if com["author"] not in unique_authors:
            unique_authors.append(com["author"])
            unique_com.append(com)
    num_com = len(unique_com)
    return unique_com[randint(0, num_com)]
def check_missed_comments():
    """Adds missed comments to the queue."""
    missed_posts = constants.DB.missed_posts.find()
    for document in missed_posts:
        url = document["url"]
        moderator = document["moderator"]
        category = document["category"]

        post = Comment(url)
        for comment in post.get_replies():
            if comment.author == moderator:
                constants.DB.missed_posts.remove({"url": url})
                age = comment.time_elapsed()
                comments = constants.DB.comments
                now = datetime.now()
                comments.insert({
                    "url": comment.authorperm,
                    "upvote_time": now + timedelta(minutes=10) - age,
                    "inserted": now,
                    "upvoted": False,
                    "category": category
                })
Example #5
0
def contribution(row, status):
    """
    Convert row to dictionary, only selecting values we want.
    """
    contribution = Contribution(row)
    url = contribution.url

    if url == "":
        return

    if contribution.staff_pick.lower() == "yes":
        staff_picked = True
    else:
        staff_picked = False

    try:
        review_date = parse(contribution.review_date)
    except Exception:
        review_date = datetime(1970, 1, 1)

    if ((datetime.now() - review_date).seconds > 561600
            and status != "unreviewed"):
        return

    total_payout = 0

    # Check if post deleted
    try:
        comment = Comment(url)
    except Exception:
        return

    if contribution.review_status == "Pending":
        for reply in comment.get_replies():
            if reply.author == contribution.moderator:
                review_date = reply["created"]
                comment_url = reply.permlink
                break
        else:
            review_date = datetime(1970, 1, 1)
            comment_url = ""
    else:
        comment_url = ""

    # Calculate total (pending) payout of contribution
    if comment.time_elapsed() > timedelta(days=7):
        total_payout = Amount(comment.json()["total_payout_value"]).amount
    else:
        total_payout = Amount(comment.json()["pending_payout_value"]).amount

    # Get votes, comments and author
    votes = comment.json()["net_votes"]
    comments = comment.json()["children"]
    author = comment.author

    # Add status for unvoted and pending
    if contribution.vote_status == "Unvoted":
        status = "unvoted"
    elif contribution.vote_status == "Pending":
        status = "pending"

    try:
        utopian_vote = Vote(f"{comment.authorperm}|utopian-io").sbd
    except Exception:
        voted_on = False
        utopian_vote = 0

    if utopian_vote:
        voted_on = True
    else:
        voted_on = False

    # Check for when contribution not reviewed
    if contribution.score == "":
        score = None
    else:
        try:
            score = float(contribution.score)
        except Exception:
            score = None

    # Create contribution dictionary and return it
    new_contribution = {
        "moderator": contribution.moderator.strip(),
        "author": author,
        "review_date": review_date,
        "url": url,
        "repository": contribution.repository,
        "category": contribution.category,
        "staff_picked": staff_picked,
        "picked_by": contribution.picked_by,
        "status": status,
        "score": score,
        "voted_on": voted_on,
        "total_payout": total_payout,
        "total_votes": votes,
        "total_comments": comments,
        "utopian_vote": utopian_vote,
        "created": comment["created"],
        "title": comment.title,
        "review_status": contribution.review_status.lower(),
        "comment_url": comment_url
    }

    return new_contribution
Example #6
0
def replied_to_comment(comment: Comment, account: str) -> typing.Optional[Comment]:
    for reply in comment.get_replies():
        if reply["author"] == account:
            return reply
    return None