Пример #1
0
    def _sql(cls, account, cached_at):
        """Prepare a SQL query from a steemd account."""
        vests = vests_amount(account['vesting_shares'])

        vote_weight = (vests
                       + vests_amount(account['received_vesting_shares'])
                       - vests_amount(account['delegated_vesting_shares']))

        proxy_weight = 0 if account['proxy'] else float(vests)
        for satoshis in account['proxied_vsf_votes']:
            proxy_weight += float(satoshis) / 1e6

        # remove empty keys
        useless = ['transfer_history', 'market_history', 'post_history',
                   'vote_history', 'other_history', 'tags_usage',
                   'guest_bloggers']
        for key in useless:
            del account[key]

        # pull out valid profile md and delete the key
        profile = safe_profile_metadata(account)
        del account['json_metadata']
        del account['posting_json_metadata']

        active_at = max(account['created'],
                        account['last_account_update'],
                        account['last_post'],
                        account['last_root_post'],
                        account['last_vote_time'])

        values = {
            'name':         account['name'],
            'created_at':   account['created'],
            'proxy':        account['proxy'],
            'post_count':   account['post_count'],
            'reputation':   rep_log10(account['reputation']),
            'proxy_weight': proxy_weight,
            'vote_weight':  vote_weight,
            'active_at':    active_at,
            'cached_at':    cached_at,

            'display_name':  profile['name'],
            'about':         profile['about'],
            'location':      profile['location'],
            'website':       profile['website'],
            'profile_image': profile['profile_image'],
            'cover_image':   profile['cover_image'],

            'raw_json': json.dumps(account)}

        # update rank field, if present
        _id = cls.get_id(account['name'])
        if _id in cls._ranks:
            values['rank'] = cls._ranks[_id]

        bind = ', '.join([k+" = :"+k for k in list(values.keys())][1:])
        return ("UPDATE hive_accounts SET %s WHERE name = :name" % bind, values)
Пример #2
0
def test_valid_account():
    raw_profile = dict(
        name='Leonardo Da Vinci',
        about='Renaissance man, vegetarian, inventor of the helicopter in 1512 and painter of the Mona Lisa.',
        location='Florence',
        website='http://www.davincilife.com/',
        cover_image='https://dsiteimages.com/0x0/https://pbs.twimg.com/profile_banners/816255358066946050/1483447009/1500x500',
        profile_image='https://www.parhlo.com/wp-content/uploads/2016/01/tmp617041537745813506.jpg',
    )
    account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile))}

    safe_profile = safe_profile_metadata(account)
    for key, safe_value in safe_profile.items():
        assert raw_profile[key] == safe_value
Пример #3
0
def test_invalid_account():
    raw_profile = dict(
        name='NameIsTooBigByOneChar',
        location='Florence\x00',
        website='davincilife.com/',
        cover_image='example.com/avatar.jpg',
        profile_image='https://example.com/valid-url-but-longer-than-1024-chars' + 'x' * 1024,
    )
    account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile))}

    safe_profile = safe_profile_metadata(account)
    assert safe_profile['name'] == 'NameIsTooBigByOne...'
    assert safe_profile['about'] == ''
    assert safe_profile['location'] == ''
    assert safe_profile['website'] == 'http://davincilife.com/' # TODO: should normalize to https?
    assert safe_profile['cover_image'] == ''
    assert safe_profile['profile_image'] == ''
Пример #4
0
    def _generate_cache_sqls(cls, accounts):
        """Prepare a SQL query from a steemd account."""
        cached_at = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
        sqls = []
        for account in SteemClient.instance().get_accounts(accounts):
            vote_weight = (vests_amount(account['vesting_shares']) +
                           vests_amount(account['received_vesting_shares']) -
                           vests_amount(account['delegated_vesting_shares']))

            # remove empty keys
            useless = [
                'transfer_history', 'market_history', 'post_history',
                'vote_history', 'other_history', 'tags_usage', 'guest_bloggers'
            ]
            for key in useless:
                del account[key]

            # pull out valid profile md and delete the key
            profile = safe_profile_metadata(account)
            del account['json_metadata']

            values = {
                'name': account['name'],
                'proxy': account['proxy'],
                'post_count': account['post_count'],
                'reputation': rep_log10(account['reputation']),
                'proxy_weight': vests_amount(account['vesting_shares']),
                'vote_weight': vote_weight,
                'kb_used': int(account['lifetime_bandwidth']) / 1e6 / 1024,
                'active_at': account['last_bandwidth_update'],
                'cached_at': cached_at,
                'display_name': profile['name'],
                'about': profile['about'],
                'location': profile['location'],
                'website': profile['website'],
                'profile_image': profile['profile_image'],
                'cover_image': profile['cover_image'],
                'raw_json': json.dumps(account)
            }

            update = ', '.join([k + " = :" + k
                                for k in list(values.keys())][1:])
            sql = "UPDATE hive_accounts SET %s WHERE name = :name" % (update)
            sqls.append((sql, values))
        return sqls
Пример #5
0
    def _sql(cls, account, cached_at):
        """Prepare a SQL query from a steemd account."""
        vote_weight = (vests_amount(account['vesting_shares']) +
                       vests_amount(account['received_vesting_shares']) -
                       vests_amount(account['delegated_vesting_shares']))

        # remove empty keys
        useless = [
            'transfer_history', 'market_history', 'post_history',
            'vote_history', 'other_history', 'tags_usage', 'guest_bloggers'
        ]
        for key in useless:
            del account[key]

        # pull out valid profile md and delete the key
        profile = safe_profile_metadata(account)
        del account['json_metadata']

        active_at = max(account['created'], account['last_post'],
                        account['last_vote_time'])

        values = {
            'name': account['name'],
            'created_at': account['created'],
            'proxy': account['proxy'],
            'post_count': account['post_count'],
            'reputation': rep_log10(account['reputation']),
            'proxy_weight': vests_amount(account['vesting_shares']),
            'vote_weight': vote_weight,
            'active_at': active_at,
            'cached_at': cached_at,
            'display_name': profile['name'],
            'about': profile['about'],
            'location': profile['location'],
            'website': profile['website'],
            'profile_image': profile['profile_image'],
            'cover_image': profile['cover_image'],
            'raw_json': json.dumps(account)
        }

        bind = ', '.join([k + " = :" + k for k in list(values.keys())][1:])
        return ("UPDATE hive_accounts SET %s WHERE name = :name" % bind,
                values)