From a3ba321e5e630bda5ed8a047c5e02db23d5cf5f1 Mon Sep 17 00:00:00 2001 From: mokurin000 <1348292515a@gmail.com> Date: Mon, 4 Aug 2025 01:55:44 +0800 Subject: [PATCH] refactor: drop players.json support --- .gitignore | 2 +- utils/{export_players.py => export_b50.py} | 28 +++------------------- utils/hasher.py | 8 +++++++ 3 files changed, 12 insertions(+), 26 deletions(-) rename utils/{export_players.py => export_b50.py} (87%) create mode 100644 utils/hasher.py diff --git a/.gitignore b/.gitignore index f943528..92f9633 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ /players*.parquet /b50*.json* -/region*.json* +/region*.parquet /.python-version /uv.lock diff --git a/utils/export_players.py b/utils/export_b50.py similarity index 87% rename from utils/export_players.py rename to utils/export_b50.py index c0ee5fc..2592dd8 100644 --- a/utils/export_players.py +++ b/utils/export_b50.py @@ -1,10 +1,10 @@ import orjson as json -import hashlib from typing import Callable from datetime import datetime from decimal import Decimal, getcontext -SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7" +from hasher import salted_hash_userid + with open("musicDB.json", "r", encoding="utf-8") as f: music_db = json.loads(f.read()) @@ -80,12 +80,6 @@ def dx_rating(difficulty: Decimal, achievement: int) -> int: return int(result) -def salted_hash_userid(player: dict): - uid = player["userId"] - hash_uid = hashlib.sha256(f"{uid}".encode("utf-8") + SALT) - player["userId"] = hash_uid.hexdigest()[:16] - - def clean_b50(b50: dict[str, str | dict]): urating: dict[str, list[dict[str, int]]] = b50["userRating"] @@ -141,17 +135,6 @@ def clean_b50(b50: dict[str, str | dict]): ) -def clean_player(player: dict): - player.pop("isLogin") - player.pop("lastLoginDate") - player.pop("lastPlayDate") - player.pop("isNetMember") - player.pop("dailyBonusDate") - player.pop("banState") - player.pop("nameplateId") - player.pop("trophyId") - - def record_time(*, _: list[datetime] = []): last_time = _ if not last_time: @@ -174,7 +157,7 @@ def process( print(f"loaded, cost {record_time():.2f}s") for entry in data: - salted_hash_userid(entry) + entry["userId"] = salted_hash_userid(entry["userId"]) clean_fields(entry) print(f"processed, cost {record_time():.2f}s") @@ -186,11 +169,6 @@ def process( def main(): - # process( - # clean_player, - # "players.json", - # "players_pub.json", - # ) process( clean_b50, "b50.json", diff --git a/utils/hasher.py b/utils/hasher.py new file mode 100644 index 0000000..fb5b7a3 --- /dev/null +++ b/utils/hasher.py @@ -0,0 +1,8 @@ +import hashlib + + +def salted_hash_userid(user_id: int): + SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7" + + hash_uid = hashlib.sha256(f"{user_id}".encode("utf-8") + SALT) + return hash_uid.hexdigest()[:16]