示例#1
0
 def test_comment(self, node_param):
     if node_param == "non_appbase":
         bts = self.bts
     else:
         bts = self.appbase
     with self.assertRaises(exceptions.ContentDoesNotExistsException):
         Comment("@abcdef/abcdef", steem_instance=bts)
     c = Comment(self.authorperm, steem_instance=bts)
     self.assertTrue(isinstance(c.id, int))
     self.assertTrue(c.id > 0)
     self.assertEqual(c.author, self.author)
     self.assertEqual(c.permlink, self.permlink)
     self.assertEqual(c.authorperm, self.authorperm)
     self.assertEqual(c.category, self.category)
     self.assertEqual(c.parent_author, '')
     self.assertEqual(c.parent_permlink, self.category)
     self.assertEqual(c.title, self.title)
     self.assertTrue(len(c.body) > 0)
     self.assertTrue(isinstance(c.json_metadata, dict))
     self.assertTrue(c.is_main_post())
     self.assertFalse(c.is_comment())
     if c.is_pending():
         self.assertFalse(
             (c.time_elapsed().total_seconds() / 60 / 60 / 24) > 7.0)
     else:
         self.assertTrue(
             (c.time_elapsed().total_seconds() / 60 / 60 / 24) > 7.0)
     self.assertTrue(isinstance(c.get_reblogged_by(), list))
     self.assertTrue(len(c.get_reblogged_by()) > 0)
     self.assertTrue(isinstance(c.get_votes(), list))
     if node_param == "appbase":
         self.assertTrue(len(c.get_votes()) > 0)
         self.assertTrue(isinstance(c.get_votes()[0], Vote))
示例#2
0
def main():
    """
    If voting power is 99.75 then it votes on the contribution with the highest
    score.
    """
    voting_power = Account(ACCOUNT).get_voting_power()
    logger.info(f"Current voting power: {voting_power}")
    if voting_power < 99.75:
        return

    rows = reviewed.get_all_values()

    # Sort rows by score
    sorted_rows = sorted(rows[1:], key=lambda x: float(x[5]), reverse=True)

    # Check if there's a staff picked contribution
    for row in sorted_rows:
        voted_for = row[-2]
        staff_picked = row[6]
        if voted_for == "Pending" and staff_picked == "Yes":
            url = row[2]
            post = Comment(url, steem_instance=steem)
            if post.time_elapsed() > timedelta(hours=MINIMUM_AGE):
                vote_update(row, rows.index(row) + 1, True)
                return

    # Otherwise check for pending contribution with highest score
    for row in sorted_rows:
        voted_for = row[-2]
        if voted_for != "Pending":
            continue

        url = row[2]
        post = Comment(url, steem_instance=steem)
        if post.time_elapsed() > timedelta(hours=MINIMUM_AGE):
            vote_update(row, rows.index(row) + 1)
            return

    logger.info(f"No eligible posts older than {MINIMUM_AGE} hours found.")
示例#3
0
 def test_comment(self):
     bts = self.bts
     with self.assertRaises(exceptions.ContentDoesNotExistsException):
         Comment("@abcdef/abcdef", steem_instance=bts)
     title = ''
     cnt = 0
     while title == '' and cnt < 5:
         c = Comment(self.authorperm, steem_instance=bts)
         title = c.title
         cnt += 1
         if title == '':
             c.blockchain.rpc.next()
             c.refresh()
             title = c.title
     self.assertTrue(isinstance(c.id, int))
     self.assertTrue(c.id > 0)
     self.assertEqual(c.author, self.author)
     self.assertEqual(c.permlink, self.permlink)
     self.assertEqual(c.authorperm, self.authorperm)
     # self.assertEqual(c.category, self.category)
     self.assertEqual(c.parent_author, '')
     # self.assertEqual(c.parent_permlink, self.category)
     # self.assertEqual(c.title, self.title)
     self.assertTrue(len(c.body) > 0)
     self.assertTrue(isinstance(c.json_metadata, dict))
     self.assertTrue(c.is_main_post())
     self.assertFalse(c.is_comment())
     if c.is_pending():
         self.assertFalse(
             (c.time_elapsed().total_seconds() / 60 / 60 / 24) > 7.0)
     else:
         self.assertTrue(
             (c.time_elapsed().total_seconds() / 60 / 60 / 24) > 7.0)
     # self.assertTrue(isinstance(c.get_reblogged_by(), list))
     # self.assertTrue(len(c.get_reblogged_by()) > 0)
     votes = c.get_votes()
     self.assertTrue(isinstance(votes, list))
     self.assertTrue(len(votes) > 0)
     self.assertTrue(isinstance(votes[0], Vote))
示例#4
0
文件: tmps.py 项目: steemtm/TMPS
def votecall():
    for b in balances:
        if len(blacklist) > 0 and b["account"] in blacklist:
            print("blacklisted user, skipping...")
            continue
        if float(b["balance"]) < 5:
            print("user under minimum balance")
            continue
        account = Account(b["account"])
        for post in account.get_blog(limit=1):
            c = Comment(post, steem_instance=stm)
            if (c.time_elapsed().total_seconds() / 60 / 60 /
                    24) > max_post_age_days:
                print("Post is to old, skipping")
                time.sleep(1)
                continue
            if (c.time_elapsed().total_seconds() / 60) < min_post_age:
                print("Post is to new, skipping")
                time.sleep(1)
                continue
            tags_ok = True
            if len(blacklist_tags) > 0 and "tags" in c:
                for t in blacklist_tags:
                    if t in c["tags"]:
                        tags_ok = False
            if not tags_ok:
                print("skipping, as one tag is blacklisted")
                time.sleep(1)
                continue
            already_voted = False
            for v in c["active_votes"]:
                if v["voter"] == upvote_account:
                    already_voted = True
            if already_voted:
                print("skipping, as already upvoted")
                continue
            upvote_weight = float(b["balance"]) / 20
            if c["author"] != b["account"]:
                print("Skipping reblog")
                continue
            if upvote_weight > 100:
                upvote_weight = 100
                print("upvote %s from %s with %.2f %%" %
                      (c["permlink"], c["author"], upvote_weight))
                c.upvote(weight=upvote_weight, voter=upvote_account)
                time.sleep(3)
                reply_body = "You have received a " + str(
                    upvote_weight
                ) + "% upvote based on your balance of " + str(
                    b["stake"]) + " TMPS!"
                c.reply(body=reply_body, author=upvote_account)
                print("sending comment")
                time.sleep(1)
                continue
            print("upvote %s from %s with %.2f %%" %
                  (c["permlink"], c["author"], upvote_weight))
            c.upvote(weight=upvote_weight, voter=upvote_account)
            time.sleep(3)
            reply_body = "You have received a " + str(
                upvote_weight) + "% upvote based on your balance of " + str(
                    b["balance"]) + " TMPS!"
            c.reply(body=reply_body, author=upvote_account)
            print("sending comment")
            time.sleep(1)
    print("Process Complete!")
    time.sleep(5)
            continue

        rshares = member["balance_rshares"] / comment_vote_divider
        if post_list[authorperm][
                "main_post"] == 1 and rshares < minimum_vote_threshold:
            continue
        elif post_list[authorperm][
                "main_post"] == 0 and rshares < minimum_vote_threshold * 2:
            continue
        try:
            c = Comment(authorperm, steem_instance=stm)
        except:
            continue
        main_post = c.is_main_post()
        already_voted = False
        if c.time_elapsed() > timedelta(hours=156):
            continue

        for v in c["active_votes"]:
            if v["voter"] in accounts:
                already_voted = True
        if already_voted:
            postTrx.update_voted(author, created, already_voted)
            continue
        vote_delay_sec = 15 * 60
        if member["upvote_delay"] is not None:
            vote_delay_sec = member["upvote_delay"]
        if c.time_elapsed() < timedelta(seconds=vote_delay_sec):
            continue

        if post_list[authorperm]["main_post"] == 0:
示例#6
0
                    '(https?://[a-zA-Z0-9.-]+/)?@?[a-zA-Z][a-zA-Z0-9.-]{1,14}[a-zA-Z0-9]/[a-zA-Z0-9-]+'
            ):
                a.transfer(transfer['from'], amount, transfer['amount']['nai'],
                           "Please send a valid post link.")
                log.info(shared_steem_instance().broadcast())
            log.error('Post doesn\'t exist. ({})'.format(transfer['memo']))
            continue

    if a.has_voted(c):
        a.transfer(transfer['from'], amount, transfer['amount']['nai'],
                   "The post has already been voted.")
        log.info(shared_steem_instance().broadcast())
        log.error('Already voted. ({})'.format(c.authorperm))
        continue

    if c.time_elapsed() > timedelta(days=config.getfloat('VOTING', 'max_age')):
        a.transfer(
            transfer['from'], amount, transfer['amount']['nai'],
            "The post is older than {!s} days.".format(
                config.getfloat('VOTING', 'max_age')))
        log.info(shared_steem_instance().broadcast())
        log.error('Too old. ({})'.format(c.authorperm))
        continue
    if c.time_elapsed() < timedelta(days=config.getfloat('VOTING', 'min_age')):
        a.transfer(
            transfer['from'], amount, transfer['amount']['nai'],
            "The post is younger than {!s} days.".format(
                config.getfloat('VOTING', 'min_age')))
        log.info(shared_steem_instance().broadcast())
        log.error('Too new. ({})'.format(c.authorperm))
        continue
示例#7
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
示例#8
0
                print("%s is not in the whitelist, skipping" % h["from"])
                continue
            if float(h["quantity"]) < min_token_amount:
                print("Below min token amount skipping...")
                continue
            try:
                c = Comment(h["memo"], steem_instance=stm)
            except:
                print("%s is not a valid url, skipping" % h["memo"])
                continue

            if c.is_comment() and only_main_posts:
                print("%s from %s is a comment, skipping" %
                      (c["permlink"], c["author"]))
                continue
            if (c.time_elapsed().total_seconds() / 60 / 60 /
                    24) > max_post_age_days:
                print("Post is to old, skipping")
                continue
            if (c.time_elapsed().total_seconds() / 60) < min_post_age:
                print("Post is to new, skipping")
                continue
            tags_ok = True
            if len(blacklist_tags) > 0 and "tags" in c:
                for t in blacklist_tags:
                    if t in c["tags"]:
                        tags_ok = False
            if not tags_ok:
                print("skipping, as one tag is blacklisted")
                continue
            already_voted = False
示例#9
0
                print("%s is not in the whitelist, skipping" % h["from"])
                continue
            if float(h["quantity"]) < min_token_amount:
                print("Below min token amount skipping...")
                continue
            try:
                c = Comment(h["memo"], steem_instance=stm)
            except:
                print("%s is not a valid url, skipping" % h["memo"])
                continue

            if c.is_comment() and only_main_posts:
                print("%s from %s is a comment, skipping" %
                      (c["permlink"], c["author"]))
                continue
            if (c.time_elapsed().total_seconds() / 60 / 60 /
                    24) > max_post_age_days:
                print("Post is to old, skipping")
                continue
            tags_ok = True
            if len(blacklist_tags) > 0 and "tags" in c:
                for t in blacklist_tags:
                    if t in c["tags"]:
                        tags_ok = False
            if not tags_ok:
                print("skipping, as one tag is blacklisted")
                continue
            already_voted = False
            for v in c["active_votes"]:
                if v["voter"] == upvote_account:
                    already_voted = True
示例#10
0
def contribution(row, status):
    """
    Convert row to dictionary, only selecting values we want.
    """
    if row[2] == "":
        return

    # Check if contribution was staff picked
    if row[6].lower() == "yes":
        staff_picked = True
    else:
        staff_picked = False

    # Try and get date, since some people don't enter it correctly
    try:
        review_date = parse(row[1])
    except Exception:
        review_date = datetime(1970, 1, 1)

    # If post > 7 days old don't check unless unreviewed
    if (datetime.now() - review_date).days > 7 and status != "unreviewed":
        return
    url = row[2]

    total_payout = 0

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

    # 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 row[9] == "Unvoted":
        status = "unvoted"
    elif row[9] == "Pending":
        status = "pending"

    # Check if contribution was voted on
    if row[9] == "Yes":
        voted_on = True
        try:
            utopian_vote = Vote(f"{comment.authorperm}|utopian-io").sbd
        except Exception:
            voted_on = False
            utopian_vote = 0
    else:
        voted_on = False
        utopian_vote = 0

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

    # Create contribution dictionary and return it
    new_contribution = {
        "moderator": row[0].strip(),
        "author": author,
        "review_date": review_date,
        "url": url,
        "repository": row[3],
        "category": row[4],
        "staff_picked": staff_picked,
        "picked_by": row[8],
        "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
    }

    return new_contribution
示例#11
0
        if post_list[authorperm]["main_post"] == 1:
            rshares = member["balance_rshares"] / comment_vote_divider
        else:
            rshares = member["balance_rshares"] / (comment_vote_divider ** 2)
        if post_list[authorperm]["main_post"] == 1 and rshares < minimum_vote_threshold:
            continue
        elif post_list[authorperm]["main_post"] == 0 and rshares < minimum_vote_threshold * 2:
            continue        
        try:
            c = Comment(authorperm, steem_instance=stm)
        except:
            continue
        main_post = c.is_main_post()
        already_voted = False
        if c.time_elapsed() > timedelta(hours=156):
            continue        
        voted_after = 900
        for v in c["active_votes"]:
            if v["voter"] in accounts:
                already_voted = True
                voted_after = (v["time"] - c["created"]).total_seconds()
        if already_voted:
            postTrx.update_voted(author, created, already_voted, voted_after)
            continue
        vote_delay_sec = 15 * 60
        if member["upvote_delay"] is not None:
            vote_delay_sec = member["upvote_delay"]
        if c.time_elapsed() < timedelta(seconds=(vote_delay_sec - upvote_delay_correction)):
            continue
        if member["last_received_vote"] is not None and (datetime.utcnow() - member["last_received_vote"]).total_seconds() / 60 < 15: