Example #1
0
 def update_in_vote(self, timestamp, weight, op):
     v = Vote(op)
     try:
         v.refresh()
         self.in_vote_timestamp.append(timestamp)
         self.in_vote_weight.append(weight)
         self.in_vote_rep.append(int(v["reputation"]))
         self.in_vote_rshares.append(int(v["rshares"]))
     except:
         print("Could not found: %s" % v)
         return
Example #2
0
    def test_vote(self):
        bts = self.bts
        vote = Vote(self.authorpermvoter, steem_instance=bts)
        self.assertEqual(self.voter, vote["voter"])
        self.assertEqual(self.author, vote["author"])
        self.assertEqual(self.permlink, vote["permlink"])

        vote = Vote(self.voter, authorperm=self.authorperm, steem_instance=bts)
        self.assertEqual(self.voter, vote["voter"])
        self.assertEqual(self.author, vote["author"])
        self.assertEqual(self.permlink, vote["permlink"])
        vote_json = vote.json()
        self.assertEqual(self.voter, vote_json["voter"])
        self.assertEqual(self.voter, vote.voter)
        self.assertTrue(vote.weight >= 0)
        self.assertTrue(vote.sbd >= 0)
        self.assertTrue(vote.rshares >= 0)
        self.assertTrue(vote.percent >= 0)
        self.assertTrue(vote.reputation is not None)
        self.assertTrue(vote.rep is not None)
        self.assertTrue(vote.time is not None)
        vote.refresh()
        self.assertEqual(self.voter, vote["voter"])
        self.assertEqual(self.author, vote["author"])
        self.assertEqual(self.permlink, vote["permlink"])
        vote_json = vote.json()
        self.assertEqual(self.voter, vote_json["voter"])
        self.assertEqual(self.voter, vote.voter)
        self.assertTrue(vote.weight >= 0)
        self.assertTrue(vote.sbd >= 0)
        self.assertTrue(vote.rshares >= 0)
        self.assertTrue(vote.percent >= 0)
        self.assertTrue(vote.reputation is not None)
        self.assertTrue(vote.rep is not None)
        self.assertTrue(vote.time is not None)
    def test_keyerror(self):
        bts = self.bts
        with self.assertRaises(exceptions.VoteDoesNotExistsException):
            Vote(construct_authorpermvoter(self.author, self.permlink,
                                           "asdfsldfjlasd"),
                 steem_instance=bts)

        with self.assertRaises(exceptions.VoteDoesNotExistsException):
            Vote(construct_authorpermvoter(self.author, "sdlfjd",
                                           "asdfsldfjlasd"),
                 steem_instance=bts)

        with self.assertRaises(exceptions.VoteDoesNotExistsException):
            Vote(construct_authorpermvoter("sdalfj", "dsfa", "asdfsldfjlasd"),
                 steem_instance=bts)
Example #4
0
 def test_vote(self, node_param):
     if node_param == "instance":
         stm = Steem(node="abc", autoconnect=False, num_retries=1)
         set_shared_steem_instance(self.bts)
         o = Vote("@gtg/ffdhu-gtg-witness-log|gandalf")
         self.assertIn(o.steem.rpc.url, self.urls)
         with self.assertRaises(NumRetriesReached):
             Vote("@gtg/ffdhu-gtg-witness-log|gandalf", steem_instance=stm)
     else:
         set_shared_steem_instance(
             Steem(node="abc", autoconnect=False, num_retries=1))
         stm = self.bts
         o = Vote("@gtg/ffdhu-gtg-witness-log|gandalf", steem_instance=stm)
         self.assertIn(o.steem.rpc.url, self.urls)
         with self.assertRaises(NumRetriesReached):
             Vote("@gtg/ffdhu-gtg-witness-log|gandalf")
def benchmark_calls(node,
                    authorpermvoter,
                    num_retries=10,
                    num_retries_call=10,
                    timeout=60):
    block_count = 0
    history_count = 0
    access_time = timeout
    follow_time = 0
    sucessfull = False
    error_msg = None
    start_total = timer()
    account_name = "gtg"

    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)

    try:
        stm = Steem(node=node,
                    num_retries=num_retries,
                    num_retries_call=num_retries_call,
                    timeout=timeout)

        start = timer()
        Vote(authorpermvoter, steem_instance=stm)
        stop = timer()
        vote_time = stop - start
        start = timer()
        c = Comment(authorperm, steem_instance=stm)
        if c.title == '':
            raise AssertionError("title must not be empty!")
        stop = timer()
        comment_time = stop - start
        start = timer()
        acc = Account(author, steem_instance=stm)
        # if acc.json()["json_metadata"] == '':
        #    raise AssertionError("json_metadata must not be empty!")
        stop = timer()
        account_time = stop - start
        sucessfull = True
        access_time = (vote_time + comment_time + account_time) / 3.0
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        sucessfull = False
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        sucessfull = False
    total_duration = float("{0:.2f}".format(timer() - start_total))
    access_time = float("{0:.3f}".format(access_time))
    return {
        'sucessfull': sucessfull,
        'node': node,
        'error': error_msg,
        'total_duration': total_duration,
        'access_time': access_time,
        'count': None
    }
Example #6
0
 def test_vote(self, node_param):
     if node_param == "instance":
         set_shared_steem_instance(self.bts)
         o = Vote(self.authorpermvoter)
         self.assertIn(o.steem.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Vote(self.authorpermvoter,
                  steem_instance=Steem(node="https://abc.d",
                                       autoconnect=False,
                                       num_retries=1))
     else:
         set_shared_steem_instance(
             Steem(node="https://abc.d", autoconnect=False, num_retries=1))
         stm = self.bts
         o = Vote(self.authorpermvoter, steem_instance=stm)
         self.assertIn(o.steem.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Vote(self.authorpermvoter)
Example #7
0
    def test_keyerror(self, node_param):
        if node_param == "non_appbase":
            bts = self.bts
        else:
            bts = self.appbase
        with self.assertRaises(exceptions.VoteDoesNotExistsException):
            Vote(construct_authorpermvoter(self.author, self.permlink,
                                           "asdfsldfjlasd"),
                 steem_instance=bts)

        with self.assertRaises(exceptions.VoteDoesNotExistsException):
            Vote(construct_authorpermvoter(self.author, "sdlfjd",
                                           "asdfsldfjlasd"),
                 steem_instance=bts)

        with self.assertRaises(exceptions.VoteDoesNotExistsException):
            Vote(construct_authorpermvoter("sdalfj", "dsfa", "asdfsldfjlasd"),
                 steem_instance=bts)
Example #8
0
    def test_vote(self):
        bts = self.bts
        self.assertTrue(len(bts.get_reward_funds(use_stored_data=False)) > 0)
        vote = Vote(self.authorpermvoter, blockchain_instance=bts)
        self.assertEqual(self.voter, vote["voter"])
        self.assertEqual(self.author, vote["author"])
        self.assertEqual(self.permlink, vote["permlink"])

        vote = Vote(self.voter,
                    authorperm=self.authorperm,
                    blockchain_instance=bts)
        self.assertEqual(self.voter, vote["voter"])
        self.assertEqual(self.author, vote["author"])
        self.assertEqual(self.permlink, vote["permlink"])
        vote_json = vote.json()
        self.assertEqual(self.voter, vote_json["voter"])
        self.assertEqual(self.voter, vote.voter)
        self.assertTrue(vote.weight >= 0)
        if vote.percent >= 0:
            self.assertTrue(vote.hbd >= 0)
            self.assertTrue(vote.rshares >= 0)
        else:
            self.assertTrue(vote.hbd < 0)
            self.assertTrue(vote.rshares < 0)

        self.assertTrue(vote.reputation is not None)
        self.assertTrue(vote.rep is not None)
        self.assertTrue(vote.time is not None)
        vote.refresh()
        self.assertEqual(self.voter, vote["voter"])
        self.assertEqual(self.author, vote["author"])
        self.assertEqual(self.permlink, vote["permlink"])
        vote_json = vote.json()
        self.assertEqual(self.voter, vote_json["voter"])
        self.assertEqual(self.voter, vote.voter)
        self.assertTrue(vote.weight >= 0)
        if vote.percent >= 0:
            self.assertTrue(vote.hbd >= 0)
            self.assertTrue(vote.rshares >= 0)
        else:
            self.assertTrue(vote.hbd < 0)
            self.assertTrue(vote.rshares < 0)
        self.assertTrue(vote.reputation is not None)
        self.assertTrue(vote.rep is not None)
        self.assertTrue(vote.time is not None)
Example #9
0
def meme_cortex(stm, account):
    memes = steemsql.query(q.memes_bidbotted())

    found = False
    j = -1
    i = 0
    while (i < len(memes.index) and found == False):
        try:
            v = Vote('rick.c137',
                     '@' + memes['author'][i] + '/' + memes['permlink'][i],
                     steem_instance=stm)
        except:
            found = True
            j = i
    if j > -1:
        c = Comment('@' + memes['author'][j] + '/' + memes['permlink'][j])
        comment_content = 'Look Morty, another bidbotted meme morty. Lets downvote it Morty. Morty look, I am AI Rick!!'
        c.reply(comment_content,
                title='Wubba Lubba Dub Dub',
                author=account,
                meta=None)
        c.downvote(voter=account)
        print('@' + memes['author'][j] + '/' + memes['permlink'][j])
Example #10
0
 def test_vote(self):
     o = Vote("@gtg/ffdhu-gtg-witness-log|gandalf")
     self.assertEqual(o.steem.rpc.url, self.url)
Example #11
0
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
    block_count = 0
    history_count = 0
    access_time = 0
    follow_time = 0
    blockchain_version = u'0.0.0'
    successful = True
    error_msg = None
    start_total = timer()
    max_batch_size = None
    threading = False
    thread_num = 16

    authorpermvoter = u"@gtg/steem-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        stm = Steem(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(steem_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        last_block = Block(last_block_id, steem_instance=stm)

        stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60)
        total_transaction = 0

        start = timer()
        for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num):
            block_no = entry.identifier
            block_count += 1
            if "block" in entry:
                trxs = entry["block"]["transactions"]
            else:
                trxs = entry["transactions"]

            for tx in trxs:
                for op in tx["operations"]:
                    total_transaction += 1
            if "block" in entry:
                block_time = parse_time(entry["block"]["timestamp"])
            else:
                block_time = parse_time(entry["timestamp"])

            if block_time > stopTime:
                last_block_id = block_no
                break
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        block_count = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        block_count = -1

    try:
        stm = Steem(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", steem_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        for acc_op in account.history_reverse(batch_size=100):
            history_count += 1
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        history_count = -1
        successful = False
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        history_count = -1
        successful = False
        # quit = True
    except Exception as e:
        error_msg = str(e)
        history_count = -1
        successful = False

    try:
        stm = Steem(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", steem_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, steem_instance=stm)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, steem_instance=stm)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, steem_instance=stm)
        stop = timer()
        account_time = stop - start
        start = timer()
        account.get_followers()
        stop = timer()
        follow_time = stop - start
        access_time = (vote_time + comment_time + account_time + follow_time) / 4.0
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        access_time = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        access_time = -1
    return {'successful': successful, 'node': node, 'error': error_msg,
            'total_duration': timer() - start_total, 'block_count': block_count,
            'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time,
            'version': blockchain_version}
Example #12
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
     if member_data[op["author"]]["last_post"] is None:
         member_data[op["author"]]["comment_upvote"] = 1
     elif addTzInfo(member_data[op["author"]]["last_post"]) < date_7_before:
         member_data[op["author"]]["comment_upvote"] = 1
     elif member_data[op["author"]]["comment_upvote"] == 1:
         member_data[op["author"]]["comment_upvote"] = 0
     member_data[op["author"]]["updated_at"] = c["created"]
     updated_member_data.append(member_data[op["author"]])
 elif op["type"] == "vote":
     if op["author"] not in accounts and op["author"] not in member_accounts:
         continue
     if op["voter"] not in member_accounts and op["voter"] not in accounts:
         continue
     if op["author"] in member_accounts and op["voter"] in accounts:
         authorperm=construct_authorperm(op["author"], op["permlink"])
         vote = Vote(op["voter"], authorperm=authorperm, steem_instance=stm)
         print("member %s upvoted with %d" % (op["author"], int(vote["rshares"])))
         member_data[op["author"]]["rewarded_rshares"] += int(vote["rshares"])
         member_data[op["author"]]["balance_rshares"] -= int(vote["rshares"])
         
         upvote_delay = member_data[op["author"]]["upvote_delay"]
         if upvote_delay is None:
             upvote_delay = 300
         performance = 0
         c = Comment(authorperm, steem_instance=stm)
         
         try:
             
             curation_rewards_SBD = c.get_curation_rewards(pending_payout_SBD=True)
             curation_SBD = curation_rewards_SBD["active_votes"][vote["voter"]]
             if vote_SBD > 0:
Example #14
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
            if member_data[op["author"]]["last_post"] is None:
                member_data[op["author"]]["comment_upvote"] = 1
            elif addTzInfo(member_data[op["author"]]["last_post"]) < date_7_before:
                member_data[op["author"]]["comment_upvote"] = 1
            elif member_data[op["author"]]["comment_upvote"] == 1:
                member_data[op["author"]]["comment_upvote"] = 0
            member_data[op["author"]]["updated_at"] = c["created"]
            updated_member_data.append(member_data[op["author"]])
        elif op["type"] == "vote":
            if op["author"] not in accounts and op["author"] not in member_accounts:
                continue
            if op["voter"] not in member_accounts and op["voter"] not in accounts:
                continue
            if op["author"] in member_accounts and op["voter"] in accounts:
                
                vote = Vote(op["voter"], authorperm=construct_authorperm(op["author"], op["permlink"]), steem_instance=stm)
                print("member %s upvoted with %d" % (op["author"], int(vote["rshares"])))
                member_data[op["author"]]["rewarded_rshares"] += int(vote["rshares"])
                member_data[op["author"]]["balance_rshares"] -= int(vote["rshares"])
                updated_member_data.append(member_data[op["author"]])

            data["permlink"] = op["permlink"]
            data["author"] = op["author"]
            data["voter"] = op["voter"]
            data["weight"] = op["weight"]
            vote_cnt += 1
        else:
            continue
        if op["type"] == "vote":
            db_data.append(data)
            last_trx_id = op["trx_id"]