From 8459b3bfdd62905dd290bd4d1e7ad68f8fbfaff1 Mon Sep 17 00:00:00 2001 From: "J. Cameron McDonald" Date: Sun, 19 Jan 2025 07:53:35 -0600 Subject: [PATCH] feat: use set priorities (#308) * feat: use set priorities * change FALLBACK from 1 to 0 to match Cockatrice logic --- magic_spoiler/__main__.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/magic_spoiler/__main__.py b/magic_spoiler/__main__.py index 5b0c012b..8f87f5d6 100644 --- a/magic_spoiler/__main__.py +++ b/magic_spoiler/__main__.py @@ -9,6 +9,7 @@ import pathlib import shutil import time +from enum import Enum from typing import IO, Any, Dict, List, Tuple, Union import requests @@ -42,6 +43,42 @@ "Enchantment" ) +class Priority(Enum): + FALLBACK = 0 + PRIMARY = 10 + SECONDARY = 20 + REPRINT = 30 + OTHER = 40 + +SET_TYPE_PRIORITY_MAP = { + "core": Priority.PRIMARY, + "expansion": Priority.PRIMARY, + + "commander": Priority.SECONDARY, + "starter": Priority.SECONDARY, + "draft_innovation": Priority.SECONDARY, + "duel_deck": Priority.SECONDARY, + + "archenemy": Priority.REPRINT, + "arsenal": Priority.REPRINT, + "box": Priority.REPRINT, + "from_the_vault": Priority.REPRINT, + "masterpiece": Priority.REPRINT, + "masters": Priority.REPRINT, + "memorabilia": Priority.REPRINT, + "planechase": Priority.REPRINT, + "premium_deck": Priority.REPRINT, + "promo": Priority.REPRINT, + "spellbook": Priority.REPRINT, + "token": Priority.REPRINT, + "treasure_chest": Priority.REPRINT, + + "alchemy": Priority.OTHER, + "funny": Priority.OTHER, + "minigame": Priority.OTHER, + "vanguard": Priority.OTHER, +} + def __get_session() -> Union[requests.Session, Any]: """ @@ -244,12 +281,14 @@ def fill_header_sets(card_xml_file: IO[Any], set_obj: Dict[str, str]) -> None: :param card_xml_file: Card file path :param set_obj: Set object """ + priority = SET_TYPE_PRIORITY_MAP.get(set_obj["set_type"].lower(), Priority.FALLBACK) card_xml_file.write( "\n" "" + set_obj["code"] + "\n" "" + set_obj["name"] + " (Spoiler)\n" "" + set_obj["set_type"].replace("_", " ").title() + "\n" "" + set_obj["released_at"] + "\n" + "" + str(priority.value) + "\n" "\n" )