Пример #1
0
    def get_post(self, post):
        if not post.author or post.author != self.author:
            return
        kwargs = {'author': post.author, 'permlink': post.slug}

        try:
            blockchain_post = Post(post=kwargs, steemd_instance=self.steem)
        except:
            return
        votes = blockchain_post.get(
            'net_votes')  # len(post.get('active_votes'))
        post.votes = votes

        # pending reward
        reward_pending_amount = blockchain_post.get(
            'total_pending_payout_value')
        amount = reward_pending_amount.get('amount')
        asset = reward_pending_amount.get('asset')
        if amount > 0:
            post.reward = amount

        self.set_asset(post, asset)

        # payouts reward
        total_payout_value = blockchain_post.get('total_payout_value')
        amount = total_payout_value.get('amount')
        asset = total_payout_value.get('asset')
        self.set_asset(post, asset)

        if amount > 0:
            post.reward = amount
            post.complete = True

        if not post.reward:
            post.save()
            return

        if post.provider == 'golos':
            # calc BTC
            local_course = self.get_local_course()
            if local_course:
                base_course = local_course.get('base')
                if base_course:
                    gbg_course = float(base_course.split(' ')[0])
                    gbg_golos = post.reward / gbg_course

                    api = Bittrex(settings.BITTREX_KEY,
                                  settings.BITTREX_SECRET)
                    btc_cost = api.get_ticker('BTC-GOLOS').get('result').get(
                        'Ask')
                    post.btc = btc_cost * gbg_golos

                    # calc RUB reward
                    rub_course = Coinapult().get_current_price(currency='RUB')
                    post.rub = post.btc * float(rub_course)
        else:
            return  # TODO set it for steem

        post.save()
Пример #2
0
    def handle_curation(self, op_type, op_value):

        curators = [c["account"] for c in get_curators()]

        # we're only interested in votes
        if op_type != "vote":
            return

        # if the voter is not a trusted curator, skip it.
        if op_value.get("voter") not in curators:
            return

        # check the post if we have already voted?
        p = Post("%s/%s" % (op_value.get("author"), op_value.get("permlink")),
                 steemd_instance=self.s)

        # we're only interested in main posts
        if not p.is_main_post():
            return

        # the post is tagged with the tags we defined?
        if len(set(self.expected_tags).intersection(p.get("tags"))) == 0:
            return

        # is the author in the blacklist?
        if is_blacklisted(op_value.get("author")):
            return

        score = 0
        already_voted = False
        curators_on_the_post = []
        for active_vote in p.get("active_votes", []):
            if active_vote.get("voter") == self.bot_account:
                already_voted = True
            if active_vote.get("voter") in curators:
                score += active_vote.get("percent")
                curators_on_the_post.append({
                    "curator":
                    active_vote.get("voter"),
                    "weight":
                    active_vote.get("percent"),
                })

        # if we already voted on that, skip.
        if already_voted:
            return

        # if the score is lower then the threshold, skip.
        if score < int(get_option(THRESHOLD_OPTION_ID)["value"]):
            return

        bot_account = Account(self.bot_account, steemd_instance=self.s)
        weight = bot_account.voting_power()
        self.upvote(p, weight, self.bot_account)
        self.post_to_webhooks(p, curators_on_the_post, score, weight)
Пример #3
0
    def get_latest_flags(self):
        flags = {}
        total_amount = 0
        account = Account(self.account_for_flag_report,
                          steemd_instance=self.steemd_instance)
        for vote in account.history_reverse(filter_by="vote"):
            if vote["weight"] > 0:
                continue
            if vote["voter"] != self.account_for_flag_report:
                continue
            ts = parse(vote["timestamp"])
            if ts < (datetime.utcnow() - timedelta(days=1)):
                break

            try:
                p = Post("%s/%s" % (vote["author"], vote["permlink"]),
                         steemd_instance=self.steemd_instance)
            except steembase.exceptions.PostDoesNotExist:
                logger.info("Couldnt load the post. %s" % vote["permlink"])
                continue

            if vote["author"] not in flags:
                flags[vote.get("author")] = {
                    "posts": 0,
                    "comments": 0,
                    "total_removed": 0
                }

            if p.is_main_post():
                flags[vote.get("author")].update(
                    {"posts": flags[vote.get("author")]["posts"] + 1})
            else:
                flags[vote.get("author")].update(
                    {"comments": flags[vote.get("author")]["comments"] + 1})

            logger.info("Analyzing %s" % self.url(p))

            for active_vote in p.get("active_votes"):
                if float(active_vote.get("rshares")) > 0:
                    continue

                if active_vote.get("voter") != self.account_for_flag_report:
                    continue

                amount_removed = self.get_payout_from_rshares(
                    active_vote.get("rshares"))
                total_amount += amount_removed

                flags[vote.get("author")].update({
                    "total_removed":
                    flags[vote.get("author")]["total_removed"] +
                    amount_removed,
                })

        return flags, round(total_amount, 2)
Пример #4
0
def update_last_post(post_id):
    global _last_post_id
    global _last_post_created

    identifier = construct_identifier(post_id['username'], post_id['permlink'])

    if identifier is not _last_post_id:
        steemd_instance = get_steem_conn()
        steem_post = Post(identifier, steemd_instance=steemd_instance)

        _last_post_id = identifier
        _last_post_created = steem_post.get('created')
Пример #5
0
def steemi_vote_up_steempython(post_id):
    identifier = construct_identifier(post_id['username'], post_id['permlink'])
    steemd_instance = get_steem_conn()

    steem_post = Post(identifier, steemd_instance=steemd_instance)

    already_voted = False
    for active_vote in steem_post.get("active_votes", []):
        if active_vote.get("voter") == STEEM_BOT_ACCOUNT:
            already_voted = True
            break

    if not already_voted:
        steem_post.vote(100, STEEM_BOT_ACCOUNT)
Пример #6
0
    def handle_data(self, plain_post):
        # Skip long comments
        if len(plain_post.get('body', '')) > 1024:
            return
        # Skip comments with no signal
        signal_found = self.check_signal(plain_post)
        if not signal_found:
            return

        post = Post(plain_post)
        # Skip comments of which depth is not 1
        if post.get('depth', 0) != 1:
            return
        parent_post_id = '@%s/%s' % (post['parent_author'],
                                     post['parent_permlink'])
        try:
            parent_post = Post(parent_post_id)
        except:
            self.log.error('Failed to get the parent post %s' % parent_post_id)
            return

        tags = parent_post.json_metadata.get('tags')
        if tags == None:
            self.log.error("No tag: " + parent_post)
            return

        if tags and self.config['main_tag'] in tags or \
            any(x.startswith(self.config['tag_prefix']) for x in tags):
            self.log.info('Found a matching comment: %s' %
                          plain_post.get('body'))
            # Save signal
            plain_post['bot_signal'] = signal_found
            plain_post['parent_post_id'] = parent_post_id
            # Select signal type
            if plain_post['bot_signal'] in self.config['report_signals']:
                plain_post['signal_type'] = 'spam'
            elif plain_post['bot_signal'] in self.config['praise_signals']:
                plain_post['signal_type'] = 'praise'
            elif plain_post['bot_signal'] in self.config['promote_signals']:
                plain_post['signal_type'] = 'promote'
            elif plain_post['bot_signal'] in self.config['welcome_signals']:
                plain_post['signal_type'] = 'welcome'
            else:
                plain_post['signal_type'] = 'unknown'
            if not self.is_valid(plain_post):
                self.log.info('Ignore not valid request')
                return
            # sink down
            self.db.queue_push('post', plain_post)
Пример #7
0
def get_post_details(s, identifier):
    try:
        p = Post(identifier)
    except Exception as error:
        return {
            "error": "Couldn't fetch the post.",
            "message": str(error),
        }

    reward_fund = s.get_reward_fund()
    reward_balance, recent_claims = reward_fund["reward_balance"], \
                                    reward_fund["recent_claims"]
    base_price = s.get_current_median_history_price()["base"]

    total_payout = 0
    bot_payout = 0
    used_bots = []
    for vote in p.get("active_votes", []):
        vote_payout = get_payout_from_rshares(vote["rshares"], reward_balance,
                                              recent_claims, base_price)

        if vote["voter"] in BOT_LIST and vote_payout > MINIMUM_RSHARE_PAYOUT:
            bot_payout += vote_payout
            used_bots.append({
                "bot": vote["voter"],
                "payout": round(vote_payout, 2),
            })

        total_payout += vote_payout

    stats = {
        "total": round(total_payout, 2),
        "bot": round(bot_payout, 2),
        "organic": round((total_payout - bot_payout), 2),
        "net_votes": p["net_votes"],
        "elapsed_time": p.time_elapsed(),
        "comment_count": p.children,
    }

    return stats
Пример #8
0
    def start_voting_round(self):
        posts = []
        for tag in self.target_tags:
            posts += self.fetch_tag(tag)
        logger.info("%s posts found.", len(posts))

        already_voted_accounts, already_voted_posts = self.last_voted_accounts_and_posts(
        )

        blacklist = self.config.get("BLACKLIST", [])
        app_whitelist = self.config.get("APP_WHITELIST", [])
        filtered_posts = []
        for post in posts:
            post_instance = Post(post, steemd_instance=self.steemd_instance)

            if not self.reputation_is_enough(post["author_reputation"]):
                continue

            if "@%s/%s" % (post.get("author"),
                           post.get("permlink")) in already_voted_posts:
                continue

            if post.get("author") in blacklist:
                continue

            if post.get("author") in already_voted_accounts:
                continue

            tag_blacklist = self.config.get("TAG_BLACKLIST", [])
            if set(tag_blacklist).intersection(post_instance.get("tags")):
                continue

            if app_whitelist:
                app = post_instance.get("json_metadata").get("app")
                if not app:
                    continue
                app_without_version = app.split("/")[0]
                if app_without_version not in app_whitelist:
                    continue

            if not self.conforms_minimum_word_count(post_instance.get("body")):
                continue

            if self.config.get("TRUSTED_ACCOUNTS"):

                # check downvotes
                found_downvote = False
                for vote in post.get("active_votes", []):
                    rshares = vote["rshares"]
                    if not isinstance(rshares, int):
                        rshares = int(rshares)

                    if vote["voter"] in self.config.get(
                            "TRUSTED_ACCOUNTS") and rshares < 0:
                        found_downvote = True
                        break

                if found_downvote:
                    logger.info(
                        "Found a downvote of trusted accounts. Skipping. %s",
                        post.identifier)
                    continue

            filtered_posts.append(post)

        logger.info("%s posts left after the filters." % len(filtered_posts))

        # Shuffle the list to make it random
        random.shuffle(filtered_posts)

        for post in filtered_posts[0:self.config["VOTE_COUNT"]]:
            if self.config.get("DEBUG"):
                print(post)
                continue

            # check cheetah commented on it
            replies = self.steemd_instance.get_content_replies(
                post.get("author"), post.get("permlink"))

            found_cheetah = False
            for reply in replies:
                if reply["author"] in ["cheetah"]:
                    found_cheetah = True
                    break

            if found_cheetah:
                logger.info(
                    "Post: %s is skipped since it's commented by cheetah.",
                    post.identifier)
                continue

            if self.in_global_blacklist(post.get("author")):
                logger.info(
                    "Post: %s is skipped since it's blacklisted globally.",
                    post.identifier)
                continue

            self.upvote(Post(post, steemd_instance=self.steemd_instance),
                        self.config["VOTE_WEIGHT"])
Пример #9
0
    if not 're-' in permlink:

        post = Post(identifier)

        if post.is_main_post():

            print(
                'Post:',
                identifier,
                'Payout:',
                str(sbd_payout),
                str(steem_payout),
                str(vesting_payout),
            )
            print('Reward:', str(post.get("total_payout_value")))
            total_claims = Amount(total_claims) + Amount(
                post.get("total_payout_value"))
            print(
                'Total Claims:',
                str(total_claims),
            )

            total_posts = total_posts + 1

            total_r_shares = 0
            booster_r_shares = 0

            for active_vote in post.get("active_votes", []):

                total_r_shares = total_r_shares + int(active_vote['rshares'])
Пример #10
0
def report():

    with open('reportlayout.txt') as layout:
        report_layout = layout.read()

    steem = Steem(node='wss://gtg.steem.house:8090')

    main_report = ('|' + column_title_thumbnail + ' | ' + column_title_author +
                   ' | ' + column_title_post_title + ' | ' +
                   column_title_payout + ' |\n' +
                   '| --- | --- | --- | --- |\n')

    total_rewards = 0
    total_posts = 0
    trailing_24h_t = time.time() - datetime.timedelta(
        minutes=1440).total_seconds()  # 24 * 60 = 1440

    stoptime = time.time()
    starttime = trailing_24h_t

    author_list = []

    for i in account.history_reverse(filter_by="vote", batch_size=10000):

        timestamp = parse_time(i['timestamp']).timestamp()

        if timestamp > trailing_24h_t:

            if i['voter'] == report_author:

                link = str('@' + i["author"] + "/" + i["permlink"])
                full_link = ('https://steemit.com/tag/' + link)
                post = Post(link)
                reward = (Amount(post.get('total_payout_value')) +
                          Amount(post.get('pending_payout_value')))
                total_posts = total_posts + 1
                tags = (post['json_metadata'].get('tags', []))
                category = post.category

                if post.is_main_post() and not i['author'] == report_author:

                    if scan_tag in tags or scan_tag in category:

                        if total_rewards == 0:

                            total_rewards = reward

                        else:

                            total_rewards = total_rewards + reward

                        try:
                            imagelink = post['json_metadata'].get('image')[0]

                        except:

                            imagelink = 'https://steem.io/images/steem.png'

                        if len(
                                imagelink
                        ) > 100:  # prevents problems with some image-links

                            imagelink = 'https://steem.io/images/steem.png'

                        image = (
                            '![main_image](https://img1.steemit.com/128x256/' +
                            imagelink + ')')

                        post_title = (post['title'])

                        if len(
                                post_title
                        ) > 30:  # cut off long titles, so the images scale properly

                            post_title = post_title[:30] + " ..."

                        if '|' in post_title:  # these symbols mess with the markdown layout

                            post_title = post_title.replace('|', ';')

                        if '[' in post_title:

                            post_title = post_title.replace('[', '')

                        if ']' in post_title:

                            post_title = post_title.replace(']', '')

                        main_report = (main_report + image + '|@' +
                                       i['author'] + '|[' + post_title + '](' +
                                       full_link + ')|' + str(reward) + '\n')

                        if not i['author'] in author_list:

                            author_list.append(i['author'])

    date = time.strftime(date_format, time.localtime(stoptime))
    report_starttime = time.strftime(time_format, time.localtime(starttime))
    report_stoptime = time.strftime(time_format, time.localtime(stoptime))
    a = Amount(total_rewards)
    average_rewards = a * (1 / total_posts)

    total_authors = len(author_list)

    dated_report_title = (report_title + str(date))

    beneficiaries = author_list

    beneficiaries.append(report_author)

    bene_list = []
    bene_weight = 10000 // len(beneficiaries)
    bene_rest = 10000 - (bene_weight * len(beneficiaries))

    for author in beneficiaries:

        bene_dict = OrderedDict()

        bene_dict['account'] = author
        bene_dict['weight'] = bene_weight

        if author == report_author:

            bene_dict['weight'] = bene_weight + bene_rest

        bene_list.append(bene_dict)

    report = report_layout

    report = report.replace('STARTTIME_GOES_HERE', str(report_starttime))
    report = report.replace('STOPTIME_GOES_HERE', str(report_stoptime))
    report = report.replace('REPORT_AUTHOR_GOES_HERE', str(report_author))
    report = report.replace('TOTAL_POSTS_GOES_HERE', str(total_posts))
    report = report.replace('TOTAL_AUTHORS_GOES_HERE', str(len(author_list)))
    report = report.replace('TOTAL_REWARDS_GOES_HERE', str(total_rewards))
    report = report.replace('AVERAGE_REWARDS_GOES_HERE', str(average_rewards))
    report = report.replace('TOTAL_BENEFICIARIES_GOES_HERE',
                            str(len(beneficiaries)))
    report = report.replace('REPORT_GOES_HERE', str(main_report))

    steem = Steem(keys=report_author_key, node='wss://gtg.steem.house:8090'
                  )  # instanciate again, for good measure

    # uncomment this to post automatically
    """ steem.post(