diff --git a/s3s.py b/s3s.py index 96b61cb..f811418 100755 --- a/s3s.py +++ b/s3s.py @@ -223,8 +223,8 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o queries.append("BankaraBattleHistoriesQuery") if specific in (True, "x"): queries.append("XBattleHistoriesQuery") - # if specific in (True, "league"): - # queries.append("LeagueBattleHistoriesQuery") # LEAGUE TODO & check query name + if specific in (True, "challenge"): + queries.append("EventBattleHistoriesQuery") if specific in (True, "private") and not utils.custom_key_exists("ignore_private", CONFIG_DATA): queries.append("PrivateBattleHistoriesQuery") if not specific: # False @@ -283,6 +283,12 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o for battle_group in query1_resp["data"]["xBattleHistories"]["historyGroups"]["nodes"]: for battle in battle_group["historyDetails"]["nodes"]: battle_ids.append(battle["id"]) + # ink battles - latest 50 challenge battles + elif "eventBattleHistories" in query1_resp["data"]: + needs_sorted = True + for battle_group in query1_resp["data"]["eventBattleHistories"]["historyGroups"]["nodes"]: + for battle in battle_group["historyDetails"]["nodes"]: + battle_ids.append(battle["id"]) # ink battles - latest 50 private battles elif "privateBattleHistories" in query1_resp["data"] \ and not utils.custom_key_exists("ignore_private", CONFIG_DATA): @@ -305,7 +311,7 @@ def fetch_json(which, separate=False, exportall=False, specific=False, numbers_o salmon_list.extend(thread_pool.map(fetch_detailed_result, [False]*len(job_ids), job_ids, [swim]*len(job_ids))) - if needs_sorted: # put regular, bankara, and private in order, since they were exported in sequential chunks + if needs_sorted: # put regular/bankara/event/private in order, b/c exported in sequential chunks try: ink_list = [x for x in ink_list if x['data']['vsHistoryDetail'] is not None] # just in case ink_list = sorted(ink_list, key=lambda d: d['data']['vsHistoryDetail']['playedTime']) @@ -498,7 +504,7 @@ def set_scoreboard(battle, tricolor=False): def prepare_battle_result(battle, ismonitoring, isblackout, overview_data=None): - '''Converts the Nintendo JSON format for a Turf War/Ranked battle to the stat.ink one.''' + '''Converts the Nintendo JSON format for a battle to the stat.ink one.''' # https://github.com/fetus-hina/stat.ink/wiki/Spl3-API:-Battle-%EF%BC%8D-Post payload = {} @@ -528,8 +534,8 @@ def prepare_battle_result(battle, ismonitoring, isblackout, overview_data=None): payload["lobby"] = "splatfest_challenge" # pro elif mode == "X_MATCH": payload["lobby"] = "xmatch" - elif mode == "LEAGUE": - pass # TODO + elif mode == "LEAGUE": # challenge + payload["lobby"] = "event" ## RULE ## ########## @@ -810,6 +816,13 @@ def prepare_battle_result(battle, ismonitoring, isblackout, overview_data=None): payload["x_power_after"] = parent["xMatchMeasurement"]["xPowerAfter"] break + ## CHALLENGES ## + ################ + if mode == "LEAGUE": + payload["event"] = battle["myTeam"]["leagueMatch"]["leagueMatchEvent"]["id"] # send in Base64 + payload["event_power"] = battle["myTeam"]["leagueMatch"]["myLeaguePower"] + # luckily no need to look at overview screen for any info + ## MEDALS ## ############ medals = [] @@ -1346,8 +1359,8 @@ def get_num_results(which): noun = utils.set_noun(which) try: - if which == "ink": # TODO update '200' number when league released - print("Note: 50 recent battles of each type (up to 200 total) may be uploaded by instead manually exporting data with " \ + if which == "ink": + print("Note: 50 recent battles of each type (up to 250 total) may be uploaded by instead manually exporting data with " \ '\033[91m' + "-o" + '\033[0m' + ".\n") n = int(input(f"Number of recent {noun} to upload (0-50)? ")) except ValueError: @@ -1362,7 +1375,7 @@ def get_num_results(which): elif which == "ink": print("\nIn this mode, s3s can only fetch the 50 most recent battles (of any type) at once. " \ "To export & upload the 50 most recent battles of each type " \ - "(Regular, Anarchy, X, and Private) for up to 200 results total, run the script with " \ + "(Regular, Anarchy, X, Challenge, and Private) for up to 2500 results total, run the script with " \ '\033[91m' + "-o" + '\033[0m' + " and then " \ '\033[91m' + "-i results.json overview.json" + '\033[0m' + ".") sys.exit(0) @@ -1416,7 +1429,7 @@ def check_if_missing(which, isblackout, istestrun, skipprefetch): # https://github.com/fetus-hina/stat.ink/wiki/Spl3-API:-Battle-%EF%BC%8D-Get-UUID-List-(for-s3s) # https://github.com/fetus-hina/stat.ink/wiki/Spl3-API:-Salmon-%EF%BC%8D-Get-UUID-List if which in ("both", "ink"): - urls.append("https://stat.ink/api/v3/s3s/uuid-list?lobby=adaptive") # max 200 entries + urls.append("https://stat.ink/api/v3/s3s/uuid-list?lobby=adaptive") # max 250 entries else: urls.append(None) if which in ("both", "salmon"): @@ -1430,7 +1443,7 @@ def check_if_missing(which, isblackout, istestrun, skipprefetch): if url is not None: printed = False auth = {'Authorization': f'Bearer {API_KEY}'} - resp = requests.get(url, headers=auth) # no params = all: regular, bankara, private + resp = requests.get(url, headers=auth) try: statink_uploads = json.loads(resp.text) except: @@ -1512,7 +1525,8 @@ def check_for_new_results(which, cached_battles, cached_jobs, battle_wins, battl splatfest_match = True if result["data"]["vsHistoryDetail"]["vsMode"]["mode"] == "FEST" else False if splatfest_match: # keys will exist our_team_name = result["data"]["vsHistoryDetail"]["myTeam"]["festTeamName"] - their_team_name = result["data"]["vsHistoryDetail"]["otherTeams"][0]["festTeamName"] # no tricolor support + their_team_name = result["data"]["vsHistoryDetail"]["otherTeams"][0]["festTeamName"] + # works for tricolor too, since all teams would be the same mirror_match = True if our_team_name == their_team_name else False if outcome == "Victory": battle_wins += 1