Created
May 16, 2022 02:54
-
-
Save pmbarrett314/4d6517cf5b68a90f1821cd8a4f94727f to your computer and use it in GitHub Desktop.
Export Arena ids
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import pathlib | |
import platform | |
import re | |
def get_platform_arena_dir(): | |
if platform.system() == "Windows": | |
return os.path.join("c:/", "Program Files", "Wizards of the Coast", | |
"MTGA", | |
"MTGA_Data", "Downloads", "Data") | |
elif platform.system() == "Darwin": | |
return os.path.join(pathlib.Path.home(), "Library", "Application Support", | |
"com.wizards.mtga", "Downloads", "Data") | |
else: | |
raise Exception("Unsupported platform") | |
def find_files(arena_dir): | |
cards_file = None | |
loc_file = None | |
for root, dirs, files in os.walk(arena_dir): | |
for file in files: | |
if re.match(r"^Data_cards_[0-9a-f]+\.mtga$", file): | |
if cards_file is not None: | |
raise Exception("two card files") | |
cards_file = os.path.join(root, file) | |
if re.match(r"^Data_loc_[0-9a-f]+\.mtga$", file): | |
if loc_file is not None: | |
raise Exception("two loc files") | |
loc_file = os.path.join(root, file) | |
return cards_file, loc_file | |
def export_arena_ids(set_=None): | |
arena_dir = get_platform_arena_dir() | |
cards_file, loc_file = find_files(arena_dir) | |
with open(cards_file) as fp: | |
card_data = json.loads(fp.read()) | |
with open(loc_file, encoding='utf-8') as fp: | |
title_data = json.loads(fp.read()) | |
card_dict = {c["titleId"]: {"grpid": c.get("grpid", None)} | |
for c in card_data | |
if not c.get("isToken", False) and (set_ is None or c["set"] == set_)} | |
lang_dict = {t["isoCode"]: t["keys"] for t in title_data} | |
for title in lang_dict["en-US"]: | |
if title["id"] in card_dict: | |
card_dict[title["id"]]["name"] = title["text"] | |
card_dict = {card_dict[k]["grpid"]: card_dict[k]["name"] for k in card_dict} | |
print(json.dumps(card_dict)) | |
if __name__ == "__main__": | |
export_arena_ids("SNC") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment