有趣生活

当前位置:首页>科技>皇室战争如何从零开始皇室战争-使用Clash

皇室战争如何从零开始皇室战争-使用Clash

发布时间:2026-07-21阅读(2)

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

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 osimport 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 Barbarians 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成立】不忘初心,方得始终。宁缺毋滥欢迎积极打部落战活跃玩家我们一直都在,只因你回头找到家。认真部落战参战打满3 1❗部落战胜率低于30%/部落战连续3次未打/周捐未200✈可请假常驻加Q群:***,

badgeId: 16000102,

clanScore: 53379,

clanWarTrophies: 13032,

location: {

id: 57000056,

name: China,

isCountry: True,

countryCode: CN

},

requiredTrophies: 5000,

donationsPerWeek: 22320,

clanChestStatus: inactive,

clanChestLevel: 1,

clanChestMaxLevel: 0,

members: 50,

memberList: [

{

tag: #URPQ8RJP,

name: DaYang,

role: member,

lastSeen: 20200308T122141.000Z,

expLevel: 13,

trophies: 5734,

arena: {

id: 54000017,

name: MasterIII

},

clanRank: 1,

previousClanRank: 3,

donations: 174,

donationsReceived: 600,

clanChestPoints: 0

}

]

}>

获取部落战信息

clan_war = client.get_clan_war(922QPY8)print(clan_war)

返回数据示例:

<Refreshable: {

state: warDay,

warEndTime: 20200308T170813.886Z,

clan: {

tag: #922QPY8,

name: 白羽部落,

badgeId: 16000102,

clanScore: 13032,

participants: 28,

battlesPlayed: 28,

wins: 14,

crowns: 28

},

participants: [

{

tag: #U2CV2UGY,

name: 龙少,

cardsEarned: 1869,

battlesPlayed: 0,

wins: 0,

collectionDayBattlesPlayed: 3,

numberOfBattles: 1

}

],

clans: [

{

tag: #CGCV0Q,

name: #BEASTGANG,

badgeId: 16000029,

clanScore: 18818,

participants: 29,

battlesPlayed: 29,

wins: 23,

crowns: 47

}

]

}>

获取玩家信息

player = client.get_player(U2CV2UGY) # 传入参数为玩家标签(个人资料中玩家名字下方#开头的一串字符串)print(player)

返回数据示例:

<Refreshable: {

tag: #U2CV2UGY,

name: 龙少,

expLevel: 13,

trophies: 5294,

bestTrophies: 5925,

wins: 5231,

losses: 5229,

battleCount: 14023,

threeCrownWins: 2842,

challengeCardsWon: 2171,

challengeMaxWins: 9,

tournamentCardsWon: 0,

tournamentBattleCount: 298,

role: coLeader,

donations: 180,

donationsReceived: 200,

totalDonations: 48591,

warDayWins: 146,

clanCardsCollected: 362035,

clan: {

tag: #922QPY8,

name: 白羽部落,

badgeId: 16000102

},

arena: {

id: 54000015,

name: MasterI

},

leagueStatistics: {

currentSeason: {

trophies: 5294,

bestTrophies: 5338

}

},

badges: [

{

name: 1000Wins,

progress: 5231

}

],

achievements: [

{

name: TeamPlayer,

stars: 3,

value: 11,

target: 1,

info: JoinaClan,

completionInfo: None

}

],

cards: [

{

name: IceGolem,

id: 26000038,

level: 7,

maxLevel: 11,

count: 812,

iconUrls: {

medium: https: //api-assets.clashroyale.com/cards/300/r05cmpwV1o7i7FHodtZwW3fmjbXCW34IJCsDEV5cZC4.png

}

}

],

currentFavouriteCard: {

name: Rascals,

id: 26000053,

maxLevel: 13,

iconUrls: {

medium: https: //api-assets.clashroyale.com/cards/300/KV48DfwVHKx9XCjzBdk3daT_Eb52Me4VgjVO7WctRc4.png

}

},

starPoints: 35636

}>

获取玩家对战信息

player_battles = client.get_player_battles(U2CV2UGY)for battle in player_battles: print(battle)

返回数据示例:

<BaseAttrDict: {

type: challenge,

battleTime: 20200307T143357.000Z,

challengeId: 73003042,

isLadderTournament: False,

arena: {

id: 54000041,

name: LegendaryArena

},

gameMode: {

id: 72000005,

name: DraftMode

},

challengeWinCountBefore: 9,

deckSelection: draft,

team: [

{

tag: #U2CV2UGY,

name: 龙少,

startingTrophies: 5294,

crowns: 2,

kingTowerHitPoints: 3500,

princessTowersHitPoints: [

900

],

clan: {

tag: #922QPY8,

name: 白羽部落,

badgeId: 16000102

},

cards: [

{

name: Lumberjack,

id: 26000035,

level: 1,

maxLevel: 5,

iconUrls: {

medium: https: //api-assets.clashroyale.com/cards/300/E6RWrnCuk13xMX5OE1EQtLEKTZQV6B78d00y8PlXt6Q.png

}

}

]

}

],

opponent: [

{

tag: #882988,

name: Ignars,

startingTrophies: 5174,

crowns: 1,

kingTowerHitPoints: 2708,

clan: {

tag: #YRJ9C0,

name: España,

badgeId: 16000172

},

cards: [

{

name: RoyalGiant,

id: 26000024,

level: 9,

maxLevel: 13,

iconUrls: {

medium: https: //api-assets.clashroyale.com/cards/300/mnlRaNtmfpQx2e6mp70sLd0ND-pKPF70Cf87_agEKg4.png

}

}

]

}

],

challengeTitle: 20200307LegendaryLadiesDraftChallenge

}>

获取玩家宝箱信息(接下来再对战x场可以获得什么宝箱)

player_chests = client.get_player_chests(U2CV2UGY)for chest in player_chests: print(chest)

返回数据示例:

<Refreshable: {index: 0, name: Golden Chest}>

<Refreshable: {index: 1, name: Silver Chest}>

<Refreshable: {index: 2, name: Silver Chest}>

<Refreshable: {index: 3, name: Silver Chest}>

<Refreshable: {index: 4, name: Silver Chest}>

<Refreshable: {index: 5, name: Magical Chest}>

<Refreshable: {index: 6, name: Silver Chest}>

<Refreshable: {index: 7, name: Silver Chest}>

<Refreshable: {index: 8, name: Golden Chest}>

<Refreshable: {index: 32, name: Giant Chest}>

<Refreshable: {index: 193, name: Mega Lightning Chest}>

<Refreshable: {index: 283, name: Epic Chest}>

<Refreshable: {index: 653, name: Legendary Chest}>

获取顶级部落清单

top_clans = client.get_top_clans(global, limit=3)for clan in top_clans: print(clan)

返回数据示例:

<Refreshable: {tag: #PPCLCJG9, name: AK Syndicate, rank: 1, previousRank: 1, location: {id: 57000249, name: United States, isCountry: True, countryCode: US}, clanScore: 65235, members: 50, badgeId: 16000044}>

<Refreshable: {tag: #PGLQ0VQ, name: Lost Orbit, rank: 2, previousRank: 2, location: {id: 57000249, name: United States, isCountry: True, countryCode: US}, clanScore: 64172, members: 50, badgeId: 16000096}>

<Refreshable: {tag: #2LUJ09CC, name: GRAND CROWN, rank: 3, previousRank: 3, location: {id: 57000122, name: Japan, isCountry: True, countryCode: JP}, clanScore: 63649, members: 49, badgeId: 16000014}>

获取顶级玩家清单

top_players = client.get_top_players(global, limit=3)for player in top_players: print(player)

返回数据示例:

<Refreshable: {tag: #8QQ8QJ99P, name: phatcat, expLevel: 13, trophies: 6975, rank: 1, previousRank: 1, clan: {tag: #29C98ULY, name: 寶貝軍團, badgeId: 16000015}, arena: {id: 54000020, name: Royal Champion}}>

<Refreshable: {tag: #CC0CLGUC, name: ☠️ SHADOW ☠️, expLevel: 13, trophies: 6958, rank: 2, previousRank: 6, clan: {tag: #98U890U, name: EGY FORCES, badgeId: 16000043}, arena: {id: 54000020, name: Royal Champion}}>

<Refreshable: {tag: #220U2GV, name: RH❄I Viiper, expLevel: 13, trophies: 6946, rank: 3, previousRank: 45, clan: {tag: #RVPJJQP, name: Pirates, badgeId: 16000078}, arena: {id: 54000020, name: Royal Champion}}>

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图