【皇室战争】使用Clash Royale API,构建你的皇室应用

Clash Royale API

通过Clash Royale API你可以准确并安全的访问皇室战争的数据,获取美妙的体验,开发令人惊叹的工具或是网站。

Clash Royale API保持和游戏本身一样的质量保准,而且持续开发和改进着。

第三方包:clashroyale

clashroyale是一个用python编写的支持异步和同步的对于官方Clash Royale API的封装。

当然,还有其他语言编写的包,如Java编写的jcrapi、PHP编写的clash-royale-php、Go编写的goroyale等等。

本文主要针对clashroyale,做简单介绍。

安装

开发版本:pip install git+https://github.com/cgrok/clashroyale

稳定版本:pip install clashroyale

使用

import os
import clashroyale


cache_fp = os.path.abspath(  # 缓存文件地址
    os.path.join(
        __file__,
        "../data"
    )
)

table_name = "clashroyale"

client = clashroyale.official_api.Client(
    token="从clashroyale官网申请的apiToken",
    is_async=False,  # 是否使用异步方式
    error_debug=False,  # 是否错误调试模式(会为每个方法都抛出异常)
    session=None,  # http会话,可以是requests.Session,也可以是aiohttp.ClientSession
    timeout=10,  # 请求API超时时间
    url='https://api.clashroyale.com/v1',  # API地址
    cache_fp=cache_fp,  # 缓存文件地址(使用sqlite3作为缓存数据库)
    cache_expires=10,  # 客户端从API请求特定路由之前等待的秒数
    table_name=table_name,  # 缓存数据表名
    camel_case=False,  # 访问数据时是否使用驼峰式的key
    constants=None,  # 使用常量
    user_agent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"  # 用户代理
)

获取所有卡牌清单

all_cards = client.get_all_cards()

for card in all_cards:
    print(card)

返回数据示例:

<Refreshable: {
    'name': 'Knight',
    'id': 26000000,
    'maxLevel': 13,
    'iconUrls': {
        'medium': 'https: //api-assets.clashroyale.com/cards/300/jAj1Q5rclXxU9kVImGqSJxa4wEMfEhvwNQ_4jiGUuqg.png'
    }
}>

获取卡牌具体信息

cat_info = client.get_card_info('Knight')
print(cat_info)

返回数据示例:

{
    'key': 'knight',
    'name': 'Knight',
    'sc_key': 'Knight',
    'elixir': 3,
    'type': 'Troop',
    'rarity': 'Common',
    'arena': 0,
    'description': "A tough melee fighter. The Barbarian's handsome, cultured cousin. Rumor has it that he was knighted based on the sheer awesomeness of his mustache alone.",
    'id': 26000000
}

获取部落信息

clan = client.get_clan('922QPY8')  # 传入参数为部落标签
print(clan)

返回数据示例:

<Refreshable: {
    'tag': '#922QPY8',
    'name': '白羽部落',
    'type': 'open',
    'description': '【2016.2.21成立】🇨🇳不忘初心,方得始终。宁缺毋滥&#

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值