feat: public export without userId
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
@@ -7,14 +8,46 @@ SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7"
|
||||
def salted_hash_userid(player: dict):
|
||||
uid = player["userId"]
|
||||
hash_uid = hashlib.sha256(f"{uid}".encode("utf-8") + SALT)
|
||||
player["userId"] = hash_uid.hexdigest()
|
||||
player["userId"] = hash_uid.hexdigest()[:16]
|
||||
|
||||
|
||||
def remove_useless_fields(player: dict):
|
||||
player.pop("isLogin")
|
||||
player.pop("lastLoginDate")
|
||||
player.pop("lastPlayDate")
|
||||
player.pop("isNetMember")
|
||||
player.pop("dailyBonusDate")
|
||||
player.pop("banState")
|
||||
|
||||
|
||||
def record_time(*, _: list[datetime] = []):
|
||||
last_time = _
|
||||
if not last_time:
|
||||
last_time.append(datetime.now())
|
||||
else:
|
||||
new = datetime.now()
|
||||
diff = (new - last_time.pop()).total_seconds()
|
||||
last_time.append(new)
|
||||
return diff
|
||||
|
||||
|
||||
def main():
|
||||
record_time()
|
||||
with open("players.json", "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
print(f"loaded, cost {record_time():.2f}s")
|
||||
|
||||
record_time()
|
||||
for entry in data:
|
||||
salted_hash_userid(entry)
|
||||
remove_useless_fields(entry)
|
||||
print(f"processed, cost {record_time():.2f}s")
|
||||
|
||||
record_time()
|
||||
with open("players_pub.json", "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False)
|
||||
print(f"written out, cost {record_time():.2f}s")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user