Пример #1
0
def pay_delegates(account, steem,
                  current_datetime,
                  min_days=3,
                  investor_share=INVESTOR_SHARE,
                  memo=MEMO):
    """ Pays delegators their share of daily SBD rewards

    Parameters
    ----------
    account: str
    steem: Steem or kwargs
    current_datetime: dateime
    min_days: int
    investor_share: float
    memo: str

    """
    logger.info('Computing payouts for delegates!')
    sbd_payouts, steem_payouts = error_retry(tpga.get_delegate_payouts)(
        account, steem,
        current_datetime=current_datetime,
        min_days=min_days,
        investor_share=investor_share
    )

    claim_all_reward_balance(steem, account)

    logger.info('Found the following SBD payouts:\n{}'.format(sbd_payouts))
    for delegator, payout in sbd_payouts.items():
        try:
            if payout:
                logger.info('Paying {} SBD to {}'.format(delegator, payout))
                error_retry(steem.commit.transfer,
                            errors=(RPCError, TypeError))(to=delegator,
                                                         amount=payout,
                                                         asset='SBD',
                                                         memo=memo,
                                                         account=account)
        except Exception as e:
            logger.exception('Could not pay {} SBD to {}! '
                             'Reconnecting...'.format(payout, delegator))
            steem.reconnect()

    logger.info('Found the following STEEM payouts:\n{}'.format(steem_payouts))
    for delegator, payout in steem_payouts.items():
        try:
            if payout:
                logger.info('Paying {} STEEM to {}'.format(delegator, payout))
                error_retry(steem.commit.transfer,
                            errors=(RPCError, TypeError))(to=delegator,
                                                         amount=payout,
                                                         asset='STEEM',
                                                         memo=memo,
                                                         account=account)
        except Exception as e:
            logger.exception('Could not pay {} STEEM to {}! '
                             'Reconnecting...'.format(payout, delegator))
            steem.reconnect()
Пример #2
0
def return_overview_permalink_if_exists(account, steem, current_datetime):
    permalink = PERMALINK_TEMPLATE.format(
        date=current_datetime.strftime('%Y-%U'))
    try:
        error_retry(Post, retries=10,
                    sleep_time=4)('@{}/{}'.format(account, permalink), steem)
        return permalink
    except PostDoesNotExist:
        return ''
Пример #3
0
 def vote(self, author, permalink, weight):
     identifier = '@{author}/{permalink}'.format(author=author,
                                                 permalink=permalink)
     logger.info('Voting on {} with weight {}.'.format(identifier,weight))
     if self.no_posting_key_mode:
         logger.warning('Test mode NOT TRYING TO VOTE!')
     else:
         error_retry(self.steem.commit.vote, retries=5,
                     sleep_time=4)(identifier=identifier,
                                             weight=weight,
                                             account=self.account)
Пример #4
0
def get_parent_posts(comment_authors_and_permalinks, steem):
    """ Scrapes posts where a reply mentioned the bot

    Parameters
    ----------
    comment_authors_and_permalinks: list of tuples
    steem: Steem object

    Returns
    -------
    List of dict
        Posts were the bot was mentioned in the replies

    """
    posts = []
    for comment_author, comment_permalink in comment_authors_and_permalinks:
        try:
            comment = error_retry(Post,
                                  errors=Exception,
                                  sleep_time=0.5,
                                  retries=7)('@{}/{}'.format(
                                      comment_author, comment_permalink),
                                             steem)

            p = error_retry(Post, errors=Exception, sleep_time=0.5,
                            retries=7)(comment.root_identifier, steem)

            post = {
                'title': p.title,
                'reward': p.reward.amount,
                'votes': len([x for x in p.active_votes if x['percent'] > 0]),
                'active_votes': p.active_votes,
                'created': p.created,
                'tags': p.tags,
                'body': p.body,
                'author': p.author,
                'permalink': p.permlink,
                'comment_author': comment_author,
                'comment_permalink': comment_permalink
            }
            posts.append(post)

        except Exception as e:
            logger.exception(('Could not work with comment {} by '
                              '{}. Reconnecting...'
                              '').format(comment_permalink, comment_author))
            steem.reconnect()

    return posts
Пример #5
0
def claim_all_reward_balance(steem, account):
    """Helper funtion to claim rewards because of bug in Steem"""
    acc = Account(account, steem)
    reward_steem = acc['reward_steem_balance']
    reward_sbd = acc['reward_sbd_balance']
    reward_vests = acc['reward_vesting_balance']
    logger.info('Claiming {}, {}, and {} for {}'.format(reward_sbd,
                                                        reward_vests,
                                                        reward_steem,
                                                        account))
    op = operations.ClaimRewardBalance(account=account,
                                       reward_steem=reward_steem,
                                       reward_sbd=reward_sbd,
                                       reward_vests=reward_vests)

    can_claim = any(Amount(x).amount > 0 for x in (reward_sbd, reward_vests, reward_steem))
    if can_claim:
        try:
            return error_retry(steem.commit.finalizeOp)(op, account, "posting")
        except Exception:
            logger.exception('Could not claim rewards {}. '
                             'Reconnecting...'.format((reward_sbd,
                                                      reward_vests,
                                                      reward_steem)))
            steem.reconnect()
    else:
        logger.info('Nothing to claim!')
Пример #6
0
def get_post_data(authors_and_permalinks, steem):
    """ Queries posts from `steem`

    Parameters
    ----------
    authors_and_permalinks: set of tuples of authors and permalink strings
    steem: Steem object

    Returns
    -------
    List of dict
        posts are kept as dicts with
            * author
            * permalink
            * title
            * body
            * reward
            * votes
            * created
            * tags

    """
    posts = []
    for kdx, (author, permalink) in enumerate(authors_and_permalinks):
        try:
            p = error_retry(Post,
                            errors=Exception,
                            sleep_time=0.5,
                            retries=3)('@{}/{}'.format(author, permalink), steem)
        except PostDoesNotExist:
            # This happens to oftern we will suppress this
            logger.debug('Post {} by {} does not exist!'.format(permalink,
                                                                author))
            continue
        except Exception:
            logger.exception('Error in loading post {} by {}. '
                             'Reconnecting...'.format(permalink, author))
            steem.reconnect()
            continue

        # Add positive votes and subtract negative
        votes = sum(1 if x['percent'] > 0 else -1 for x in p.active_votes)

        post = {
            'title': p.title,
            'reward': p.reward.amount,
            'votes':votes,
            'active_votes': p.active_votes,
            'created': p.created,
            'tags': p.tags,
            'body': p.body,
            'author': author,
            'permalink': permalink,
            'author_reputation': int(p.author_reputation)
        }
        posts.append(post)
    return posts
Пример #7
0
 def post(self, body, title, permalink, tags, self_vote=False):
     if self_vote == THRESHOLD:
         self_vote = self.check_if_self_vote()
     self.time2last_post()
     logger.info('Posting: `{}` (`{}`)\n{}'.format(title, permalink, body))
     if self.no_posting_key_mode:
         logger.warning('Test mode NOT TRYING TO POST')
     else:
         return error_retry(self.steem.commit.post, retries=10,
                     sleep_time=4, errors=Exception)(author=self.account,
                                            title=title,
                                            body=body,
                                            permlink=permalink,
                                            self_vote=self_vote,
                                            tags=tags)
Пример #8
0
    def reply(self, body, parent_author, parent_permalink, self_vote=False,
              parent_vote_weight=0):
        identifier = '@{author}/{permalink}'.format(author=parent_author,
                                                    permalink=parent_permalink)

        if parent_vote_weight:
            self.vote(parent_author, parent_permalink, parent_vote_weight)

        if self_vote == THRESHOLD:
            self_vote = self.check_if_self_vote()

        self.time2last_post()
        logger.info('Replying to {} with\n{}'.format(identifier, body))
        if self.no_posting_key_mode:
            logger.warning('Test mode NOT TRYING TO REPLY')
        else:
            return error_retry(self.steem.commit.post, retries=10,
                        sleep_time=4, errors=Exception)("",
                                              body,
                                              json_metadata=None,
                                              author=self.account,
                                              reply_identifier=identifier,
                                              self_vote=self_vote)
Пример #9
0
def test_no_logrpc_retry():
    with pytest.raises(RPCError):
        error_retry(f,
                    sleep_time=0.01,
                    errors=RPCError,
                    not_log_errors=(RPCError, ))()
Пример #10
0
def test_rpc_retry():
    with pytest.raises(RPCError):
        error_retry(f, sleep_time=0.01, errors=RPCError)()