Skip to content

Instantly share code, notes, and snippets.

@lockdef
Last active November 27, 2021 15:02
Show Gist options
  • Save lockdef/4151304a7aaee0aa95c8987d80f123b4 to your computer and use it in GitHub Desktop.
Save lockdef/4151304a7aaee0aa95c8987d80f123b4 to your computer and use it in GitHub Desktop.
Minecraft Java Editionのプレイヤーごとの進捗達成数を数え上げ、ランキングを作成する。worldファイル内のadvancementsファイル内で実行することを想定している。
import requests, glob, json, datetime, re
UUDI_TO_PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/{uuid}"
achivements_pattern = re.compile(r'minecraft:(story|nether|end|adventure|husbandry)/.*')
files = glob.glob("*.json")
user = {}
for file in files:
uuid = file.split(".")[0]
res_json = requests.get(UUDI_TO_PROFILE_URL.format(uuid=uuid)).json()
username = res_json["name"]
if username not in user.keys():
user[username] = {"count": 0, "time": datetime.datetime(1970, 1, 1, 0, 0, 0)}
with open(file, "r") as f:
data = json.load(f)
for key in data.keys():
if achivements_pattern.match(key) and data[key]["done"]:
user[username]["count"] += 1
for date in data[key]["criteria"].values():
date = " ".join(date.split()[0:2])
date = datetime.datetime.fromisoformat(date)
if date > user[username]["time"]:
user[username]["time"] = date
user = sorted(user.items(), key=lambda x: (-x[1]["count"], x[1]["time"]))
print(" 順位 | ユーザー名 | 達成数 | 時間")
print("----------------------------------------------")
for i, u in enumerate(user):
username = u[0]
count = u[1]["count"]
time = u[1]["time"].strftime('%H:%M:%S')
print(f" {(i+1):2} | {username.center(16)} | {count:2} | {time}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment