middleware_etl.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:dota2-messenger-platform 作者: nico-arianto 项目源码 文件源码
def __fill_player(data, api, account_id):
    LOGGER.info('Find account id: %d', account_id)
    # Important: Cannot utilize steamids with account_ids, because the orders of returned players was not in the same sequence and no account id in the response.
    try:
        players = api.get_player_summaries(steamids=account_id)
    except (APIError, APITimeoutError) as error:
        LOGGER.error('Failed to retrieved account id: %d and for now it will be recorded with minimum info, error: %s',
                     account_id, str(error))
        # Temporary creates a blank account with consideration that this account will be synch up again in the next fill_database_detail() invocation.
        players = {
            'players': [
                {
                    'steamid': account_id,
                    'profileurl': 'N/A'
                }
            ]
        }
    if players is None:
        LOGGER.info('Not found account id: %d', account_id)
        return False
    for player in players['players']:
        steam_id = player['steamid']
        real_name = player.get('realname', None)
        persona_name = player.get('personaname', None)
        avatar = player.get('avatarfull', None)
        profile_url = player.get('profileurl', None)
        data_player = data.get_player(account_id=account_id)
        try:
            if data_player:
                data_player.steam_id = steam_id
                data_player.real_name = real_name
                data_player.persona_name = persona_name
                data_player.avatar = avatar
                data_player.profile_url = profile_url
                data.update_player(player=data_player)
                LOGGER.info('Updated account id: %d', account_id)
            else:
                data.add_player(account_id=account_id,
                                steam_id=steam_id,
                                profile_url=profile_url,
                                real_name=real_name,
                                persona_name=persona_name,
                                avatar=avatar)
                LOGGER.info('Created account id: %d', account_id)
            return True
        except DatabaseError as error:  # Temporary ignore the unsupported data, especially the unicode issue.
            LOGGER.error('Failed to process account id: %d, error: %s', account_id, str(error))
            Database.session.rollback()
    return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号