text
stringlengths
1
93.6k
def fetch_json(which, separate=False, exportall=False, specific=False, numbers_only=False, printout=False, skipprefetch=False):
'''Returns results JSON from SplatNet 3, including a combined dictionary for battles + SR jobs if requested.'''
swim = SquidProgress()
if DEBUG:
print(f"* fetch_json() called with which={which}, separate={separate}, " \
f"exportall={exportall}, specific={specific}, numbers_only={numbers_only}")
if exportall and not separate:
print("* fetch_json() must be called with separate=True if using exportall.")
sys.exit(1)
if not skipprefetch:
prefetch_checks(printout)
if DEBUG:
print("* prefetch_checks() succeeded")
else:
if DEBUG:
print("* skipping prefetch_checks()")
swim()
ink_list, salmon_list = [], []
parent_files = []
queries = []
if which in ("both", "ink"):
if specific in (True, "regular"):
queries.append("RegularBattleHistoriesQuery")
if specific in (True, "anarchy"):
queries.append("BankaraBattleHistoriesQuery")
if specific in (True, "x"):
queries.append("XBattleHistoriesQuery")
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
if DEBUG:
print("* not specific, just looking at latest")
queries.append("LatestBattleHistoriesQuery")
else:
queries.append(None)
if which in ("both", "salmon"):
queries.append("CoopHistoryQuery")
else:
queries.append(None)
needs_sorted = False # https://ygdp.yale.edu/phenomena/needs-washed :D
for sha in queries:
if sha is not None:
if DEBUG:
print(f"* making query1 to {sha}")
lang = 'en-US' if sha == "CoopHistoryQuery" else None
sha = utils.translate_rid[sha]
battle_ids, job_ids = [], []
query1 = requests.post(iksm.GRAPHQL_URL,
data=utils.gen_graphql_body(sha),
headers=headbutt(forcelang=lang),
cookies=dict(_gtoken=GTOKEN))
query1_resp = json.loads(query1.text)
swim()
if not query1_resp.get("data"): # catch error
print("\nSomething's wrong with one of the query hashes. Ensure s3s is up-to-date, and if this message persists, please open an issue on GitHub.")
sys.exit(1)
# ink battles - latest 50 of any type
if "latestBattleHistories" in query1_resp["data"]:
for battle_group in query1_resp["data"]["latestBattleHistories"]["historyGroups"]["nodes"]:
for battle in battle_group["historyDetails"]["nodes"]:
battle_ids.append(battle["id"]) # don't filter out private battles here - do that in post_result()
# ink battles - latest 50 turf war
elif "regularBattleHistories" in query1_resp["data"]:
needs_sorted = True
for battle_group in query1_resp["data"]["regularBattleHistories"]["historyGroups"]["nodes"]:
for battle in battle_group["historyDetails"]["nodes"]:
battle_ids.append(battle["id"])
# ink battles - latest 50 anarchy battles
elif "bankaraBattleHistories" in query1_resp["data"]:
needs_sorted = True
for battle_group in query1_resp["data"]["bankaraBattleHistories"]["historyGroups"]["nodes"]:
for battle in battle_group["historyDetails"]["nodes"]:
battle_ids.append(battle["id"])
# ink battles - latest 50 x battles
elif "xBattleHistories" in query1_resp["data"]:
needs_sorted = True
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