steam.py 文件源码

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

项目:PaddoCogs 作者: PaddoInWonderland 项目源码 文件源码
def _app_info(self, gid):
        url = 'http://store.steampowered.com/api/appdetails?'
        payload = {}
        payload['appids'] = gid
        headers = {'user-agent': 'Red-cog/1.0'}
        conn = aiohttp.TCPConnector(verify_ssl=False)
        session = aiohttp.ClientSession(connector=conn)
        async with session.get(url, params=payload, headers=headers) as r:
            data = await r.json()
        session.close()
        if data[str(gid)]['success']:
            data = data[str(gid)]['data']
            info = {}
            info['name'] = data['name']
            info['developers'] = data['developers']
            info['publishers'] = data['publishers']

            if data['is_free']:
                info['price'] = 'Free to Play'
            elif 'price_overview' not in data:
                info['price'] = 'Not available'
            else:
                info['price'] = '{} {}'.format(str(data['price_overview']['final'] / 100), (data['price_overview']['currency']))
                if data['price_overview']['discount_percent'] > 0:
                    info['price'] = '{} {} ({} -{}%)'.format(str(data['price_overview']['final'] / 100), data['price_overview']['currency'], str(data['price_overview']['initial'] / 100), str(data['price_overview']['discount_percent']))
            if data['release_date']['coming_soon']:
                info['release_date'] = 'Coming Soon'
            else:
                info['release_date'] = data['release_date']['date']
            info['genres'] = data['genres']
            info['recommendations'] = ''
            if 'recommendations' in data:
                info['recommendations'] = 'Recommendations: {}\n\n'.format(str(data['recommendations']['total']))
            info['about_the_game'] = re.sub("<.*?>", " ", data['about_the_game'].replace('  ', '').replace('\r', '').replace('<br>', '\n').replace('\t', ''))
            if len(info['about_the_game']) > 500:
                info['about_the_game'] = '{}...'.format(info['about_the_game'][:500-3])
            return info
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号