refactor: drop players.json support
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
/players*.parquet
|
/players*.parquet
|
||||||
/b50*.json*
|
/b50*.json*
|
||||||
/region*.json*
|
/region*.parquet
|
||||||
|
|
||||||
/.python-version
|
/.python-version
|
||||||
/uv.lock
|
/uv.lock
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import orjson as json
|
import orjson as json
|
||||||
import hashlib
|
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal, getcontext
|
from decimal import Decimal, getcontext
|
||||||
|
|
||||||
SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7"
|
from hasher import salted_hash_userid
|
||||||
|
|
||||||
|
|
||||||
with open("musicDB.json", "r", encoding="utf-8") as f:
|
with open("musicDB.json", "r", encoding="utf-8") as f:
|
||||||
music_db = json.loads(f.read())
|
music_db = json.loads(f.read())
|
||||||
@@ -80,12 +80,6 @@ def dx_rating(difficulty: Decimal, achievement: int) -> int:
|
|||||||
return int(result)
|
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]):
|
def clean_b50(b50: dict[str, str | dict]):
|
||||||
urating: dict[str, list[dict[str, int]]] = b50["userRating"]
|
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] = []):
|
def record_time(*, _: list[datetime] = []):
|
||||||
last_time = _
|
last_time = _
|
||||||
if not last_time:
|
if not last_time:
|
||||||
@@ -174,7 +157,7 @@ def process(
|
|||||||
print(f"loaded, cost {record_time():.2f}s")
|
print(f"loaded, cost {record_time():.2f}s")
|
||||||
|
|
||||||
for entry in data:
|
for entry in data:
|
||||||
salted_hash_userid(entry)
|
entry["userId"] = salted_hash_userid(entry["userId"])
|
||||||
clean_fields(entry)
|
clean_fields(entry)
|
||||||
print(f"processed, cost {record_time():.2f}s")
|
print(f"processed, cost {record_time():.2f}s")
|
||||||
|
|
||||||
@@ -186,11 +169,6 @@ def process(
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# process(
|
|
||||||
# clean_player,
|
|
||||||
# "players.json",
|
|
||||||
# "players_pub.json",
|
|
||||||
# )
|
|
||||||
process(
|
process(
|
||||||
clean_b50,
|
clean_b50,
|
||||||
"b50.json",
|
"b50.json",
|
||||||
8
utils/hasher.py
Normal file
8
utils/hasher.py
Normal file
@@ -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]
|
||||||
Reference in New Issue
Block a user