text
stringlengths
1
93.6k
if overview_data is not None:
ranked_list = []
for screen in overview_data:
if "bankaraBattleHistories" in screen["data"]:
ranked_list = screen["data"]["bankaraBattleHistories"]["historyGroups"]["nodes"]
break
elif "latestBattleHistories" in screen["data"]: # early exports used this, and no bankaraMatchChallenge below
ranked_list = screen["data"]["latestBattleHistories"]["historyGroups"]["nodes"]
break
for parent in ranked_list: # groups in overview (anarchy tab) JSON/screen
for idx, child in enumerate(parent["historyDetails"]["nodes"]):
# same battle, different screens
overview_battle_id = base64.b64decode(child["id"]).decode('utf-8')
overview_battle_id_mutated = overview_battle_id.replace("BANKARA", "RECENT")
if overview_battle_id_mutated == battle_id_mutated: # found the battle ID in the other file
full_rank = re.split('([0-9]+)', child["udemae"].lower())
was_s_plus_before = len(full_rank) > 1 # true if "before" rank is s+
payload["rank_before"] = full_rank[0]
if was_s_plus_before:
payload["rank_before_s_plus"] = int(full_rank[1])
# anarchy battle (series) - not open
if "bankaraMatchChallenge" in parent and parent["bankaraMatchChallenge"] is not None:
# rankedup = parent["bankaraMatchChallenge"]["isUdemaeUp"]
ranks = ["c-", "c", "c+", "b-", "b", "b+", "a-", "a", "a+", "s"] # s+ handled separately
# rank-up battle
if parent["bankaraMatchChallenge"]["isPromo"] == True:
payload["rank_up_battle"] = "yes"
else:
payload["rank_up_battle"] = "no"
if parent["bankaraMatchChallenge"]["udemaeAfter"] is not None:
if idx != 0:
payload["rank_after"] = payload["rank_before"]
if was_s_plus_before: # not a rank-up battle, so must be the same
payload["rank_after_s_plus"] = payload["rank_before_s_plus"]
else: # the battle where we actually ranked up
full_rank_after = re.split('([0-9]+)', parent["bankaraMatchChallenge"]["udemaeAfter"].lower())
payload["rank_after"] = full_rank_after[0]
if len(full_rank_after) > 1:
payload["rank_after_s_plus"] = int(full_rank_after[1])
if idx == 0: # for the most recent battle in the series only
# send overall win/lose count
payload["challenge_win"] = parent["bankaraMatchChallenge"]["winCount"]
payload["challenge_lose"] = parent["bankaraMatchChallenge"]["loseCount"]
# send exp change (gain)
if payload["rank_exp_change"] is None:
payload["rank_exp_change"] = parent["bankaraMatchChallenge"]["earnedUdemaePoint"]
if DEBUG:
print(f'* {battle["judgement"]} {idx}')
print(f'* rank_before: {payload["rank_before"]}')
print(f'* rank_after: {payload["rank_after"]}')
print(f'* rank up battle: {parent["bankaraMatchChallenge"]["isPromo"]}')
print(f'* is ranked up: {parent["bankaraMatchChallenge"]["isUdemaeUp"]}')
if idx == 0:
print(f'* rank_exp_change: {parent["bankaraMatchChallenge"]["earnedUdemaePoint"]}')
else:
print(f'* rank_exp_change: 0')
break # found the child ID, no need to continue
## X BATTLES ##
###############
if mode == "X_MATCH":
# counts & knockout set in 'basic info'
if battle["xMatch"]["lastXPower"] is not None:
payload["x_power_before"] = battle["xMatch"]["lastXPower"]
battle_id = base64.b64decode(battle["id"]).decode('utf-8')
battle_id_mutated = battle_id.replace("XMATCH", "RECENT")
if overview_data is None: # no passed in file with -i
overview_post = requests.post(iksm.GRAPHQL_URL,
data=utils.gen_graphql_body(utils.translate_rid["XBattleHistoriesQuery"]),
headers=headbutt(),
cookies=dict(_gtoken=GTOKEN))
try:
overview_data = [json.loads(overview_post.text)] # make the request in real-time in attempt to get rank, etc.
except:
overview_data = None
print("Failed to get recent X Battles. Proceeding without some information on X Power.")
if overview_data is not None:
x_list = []
for screen in overview_data:
if "xBattleHistories" in screen["data"]:
x_list = screen["data"]["xBattleHistories"]["historyGroups"]["nodes"]
break
for parent in x_list: # groups in overview (x tab) JSON/screen
for idx, child in enumerate(parent["historyDetails"]["nodes"]):
overview_battle_id = base64.b64decode(child["id"]).decode('utf-8')
overview_battle_id_mutated = overview_battle_id.replace("XMATCH", "RECENT")