text
stringlengths
1
93.6k
noun = "jobs" # for second run through the loop
which = "salmon"
def check_for_new_results(which, cached_battles, cached_jobs, battle_wins, battle_losses, battle_draws, splatfest_wins, splatfest_losses, splatfest_draws, mirror_matches, job_successes, job_failures, isblackout, istestrun):
'''Helper function for monitor_battles(), called every N seconds or when exiting.'''
# ! fetch from online
# check only numbers (quicker); specific=False since checks recent (latest) only
try:
ink_results, salmon_results = fetch_json(which, separate=True, numbers_only=True)
except: # e.g. JSONDecodeError - tokens have probably expired
gen_new_tokens("expiry") # we don't have to do prefetch_checks(), we know they're expired. gen new ones and try again
ink_results, salmon_results = fetch_json(which, separate=True, numbers_only=True)
foundany = False
if which in ("both", "ink"):
for num in reversed(ink_results):
if num not in cached_battles:
# get the full battle data
result_post = requests.post(iksm.GRAPHQL_URL,
data=utils.gen_graphql_body(utils.translate_rid["VsHistoryDetailQuery"], "vsResultId", num),
headers=headbutt(),
cookies=dict(_gtoken=GTOKEN))
result = json.loads(result_post.text)
if result["data"]["vsHistoryDetail"]["vsMode"]["mode"] == "PRIVATE" \
and utils.custom_key_exists("ignore_private", CONFIG_DATA):
pass
else:
foundany = True
if result["data"]["vsHistoryDetail"]["judgement"] == "WIN":
outcome = "Victory"
elif result["data"]["vsHistoryDetail"]["judgement"] in ("LOSE", "DEEMED_LOSE", "EXEMPTED_LOSE"):
outcome = "Defeat"
else:
outcome = "Draw"
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"]
# 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
if splatfest_match and not mirror_match:
splatfest_wins += 1
elif outcome == "Defeat":
battle_losses += 1
if splatfest_match and not mirror_match:
splatfest_losses += 1
else:
battle_draws += 1
if splatfest_match and not mirror_match:
splatfest_draws += 1
if splatfest_match and mirror_match:
mirror_matches += 1
stagename = result["data"]["vsHistoryDetail"]["vsStage"]["name"]
shortname = stagename.split(" ")[-1]
if shortname == "d'Alfonsino": # lol franch
shortname = "Museum"
elif shortname == "Co.":
shortname = "Cargo"
endtime = utils.epoch_time(result["data"]["vsHistoryDetail"]["playedTime"]) + \
result["data"]["vsHistoryDetail"]["duration"]
dt = datetime.datetime.fromtimestamp(endtime).strftime('%I:%M:%S %p').lstrip("0")
print(f"New battle result detected at {dt}! ({shortname}, {outcome})")
cached_battles.append(num)
post_result(result, True, isblackout, istestrun) # True = is monitoring mode
if which in ("both", "salmon"):
for num in reversed(salmon_results):
if num not in cached_jobs:
# get the full job data
result_post = requests.post(iksm.GRAPHQL_URL,
data=utils.gen_graphql_body(utils.translate_rid["CoopHistoryDetailQuery"], "coopHistoryDetailId", num),
headers=headbutt(forcelang='en-US'),
cookies=dict(_gtoken=GTOKEN))
result = json.loads(result_post.text)
if result["data"]["coopHistoryDetail"]["jobPoint"] is None \
and utils.custom_key_exists("ignore_private_jobs", CONFIG_DATA): # works pre- and post-2.0.0
pass
else:
foundany = True
outcome = "Clear" if result["data"]["coopHistoryDetail"]["resultWave"] == 0 else "Defeat"
if outcome == "Clear":
job_successes += 1
else:
job_failures += 1
stagename = result["data"]["coopHistoryDetail"]["coopStage"]["name"]
shortname = stagename.split(" ")[-1] # fine for salmon run stage names too
endtime = utils.epoch_time(result["data"]["coopHistoryDetail"]["playedTime"])
dt = datetime.datetime.fromtimestamp(endtime).strftime('%I:%M:%S %p').lstrip("0")
print(f"New job result detected at {dt}! ({shortname}, {outcome})")