From 8dcff70b465e9343d93cf6d09ec2b86a754d3a6e Mon Sep 17 00:00:00 2001 From: eli fessler Date: Tue, 27 Sep 2022 03:40:53 -1000 Subject: [PATCH] check old & new uuids to prevent duplicate uploads with -r flag (#29) --- s3s.py | 30 ++++++++++++++++++------------ utils.py | 4 ++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/s3s.py b/s3s.py index 225a255..123f272 100755 --- a/s3s.py +++ b/s3s.py @@ -391,8 +391,7 @@ def prepare_battle_result(battle, ismonitoring, overview_data=None): ## UUID ## ########## full_id = utils.b64d(battle["id"]) - s3s_namespace = uuid.UUID('b3a2dbf5-2c09-4792-b78c-00b548b70aeb') - payload["uuid"] = str(uuid.uuid5(s3s_namespace, full_id[-52:])) # input format: T_ + payload["uuid"] = str(uuid.uuid5(utils.S3S_NAMESPACE, full_id[-52:])) # input format: T_ ## MODE ## ########## @@ -846,16 +845,24 @@ def check_if_missing(which, ismonitoring, isblackout, istestrun): sys.exit(1) # ! fetch from online - splatnet_hashes = fetch_json(which, specific=True, numbers_only=True) # 'specific' - check ALL possible battles + splatnet_ids = fetch_json(which, specific=True, numbers_only=True) # 'specific' - check ALL possible battles - for hash in reversed(splatnet_hashes): # earliest to most recent - uuid = utils.b64d(hash) - if uuid not in statink_uploads: # one of the splatnet entries isn't on stat.ink (unuploaded) - if not printed: - printed = True - print(f"Previously-unuploaded {noun} detected. Uploading now...") + # same as code in -i section below... + for id in reversed(splatnet_ids): + full_id = utils.b64d(id) + old_uuid = full_id[-36:] + new_uuid = str(uuid.uuid5(utils.S3S_NAMESPACE, full_id[-52:])) - fetch_and_upload_single_result(hash, noun, ismonitoring, isblackout, istestrun) + if new_uuid in statink_uploads: + continue + if old_uuid in statink_uploads: + if not utils.custom_key_exists("force_uploads", CONFIG_DATA): + continue + if not printed: + printed = True + print(f"Previously-unuploaded {noun} detected. Uploading now...") + + fetch_and_upload_single_result(id, noun, ismonitoring, isblackout, istestrun) if not printed: print(f"No previously-unuploaded {noun} found.") @@ -1126,8 +1133,7 @@ def main(): if battle["data"]["vsHistoryDetail"] != None: full_id = utils.b64d(battle["data"]["vsHistoryDetail"]["id"]) old_uuid = full_id[-36:] # not unique because nintendo hates us - s3s_namespace = uuid.UUID('b3a2dbf5-2c09-4792-b78c-00b548b70aeb') - new_uuid = str(uuid.uuid5(s3s_namespace, full_id[-52:])) + new_uuid = str(uuid.uuid5(utils.S3S_NAMESPACE, full_id[-52:])) if new_uuid in statink_uploads: print("Skipping already-uploaded battle.") diff --git a/utils.py b/utils.py index 443500a..9f19c89 100644 --- a/utils.py +++ b/utils.py @@ -1,13 +1,13 @@ # (ↄ) 2017-2022 eli fessler (frozenpandaman), clovervidia # https://github.com/frozenpandaman/s3s # License: GPLv3 -import base64, datetime, json, re, requests +import base64, datetime, json, re, requests, uuid from bs4 import BeautifulSoup - SPLATNET3_URL = "https://api.lp1.av5ja.srv.nintendo.net" GRAPHQL_URL = "https://api.lp1.av5ja.srv.nintendo.net/api/graphql" WEB_VIEW_VERSION = "1.0.0-63bad6e1" # fallback +S3S_NAMESPACE = uuid.UUID('b3a2dbf5-2c09-4792-b78c-00b548b70aeb') # SHA256 hash database for SplatNet 3 GraphQL queries # full list: https://github.com/samuelthomas2774/nxapi/discussions/11#discussioncomment-3737698