mirror of
https://github.com/Cockatrice/Magic-Spoiler.git
synced 2026-03-21 17:54:59 -05:00
Fix Zendikar issues
Signed-off-by: ZeldaZach <zahalpern+github@gmail.com>
This commit is contained in:
parent
a54349b037
commit
69fac381f9
|
|
@ -1,13 +1,12 @@
|
|||
"""
|
||||
Handle Scryfall Spoilers
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
import shutil
|
||||
|
||||
import contextvars
|
||||
import datetime
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import shutil
|
||||
import time
|
||||
from typing import IO, Any, Dict, List, Tuple, Union
|
||||
|
||||
|
|
@ -98,15 +97,15 @@ def build_types(sf_card: Dict[str, Any]) -> Tuple[List[str], str, List[str]]:
|
|||
|
||||
type_line = sf_card["type_line"]
|
||||
|
||||
if u"—" in type_line:
|
||||
card_subs = type_line.split(u"—")[1].strip()
|
||||
if "—" in type_line:
|
||||
card_subs = type_line.split("—")[1].strip()
|
||||
sub_types = card_subs.split(" ") if " " in card_subs else [card_subs]
|
||||
|
||||
for card_type in all_super_types:
|
||||
if card_type in type_line:
|
||||
super_types.append(card_type)
|
||||
|
||||
types: str = type_line.split(u"—")[0]
|
||||
types: str = type_line.split("—")[0]
|
||||
for card_type in all_super_types:
|
||||
types = types.replace(card_type, "")
|
||||
|
||||
|
|
@ -156,30 +155,43 @@ def scryfall2mtgjson(scryfall_cards: List[Dict[str, Any]]) -> List[Dict[str, Any
|
|||
for sf_card in composed_sf_cards:
|
||||
super_types, types, sub_types = build_types(sf_card)
|
||||
|
||||
trice_card = {
|
||||
"cmc": sf_card["cmc"],
|
||||
"names": sf_card.get("names", None),
|
||||
"mana_cost": sf_card.get("mana_cost", ""),
|
||||
"name": sf_card["name"],
|
||||
"number": sf_card["collector_number"],
|
||||
"rarity": sf_card["rarity"].replace("mythic", "mythic rare").title(),
|
||||
"text": sf_card.get("oracle_text", ""),
|
||||
"url": sf_card["image_uris"].get("normal", "").rsplit("?", 1)[0],
|
||||
"type": sf_card.get("type_line", "Unknown").replace(u"—", "-"),
|
||||
"colorIdentity": sf_card.get("color_identity", None),
|
||||
"colors": sf_card["colors"],
|
||||
"power": sf_card.get("power", None),
|
||||
"toughness": sf_card.get("toughness", None),
|
||||
"layout": sf_card["layout"].replace("normal", ""),
|
||||
"loyalty": sf_card.get("loyalty", None),
|
||||
"artist": sf_card.get("artist", ""),
|
||||
"flavor": sf_card.get("flavor_text", None),
|
||||
"multiverseId": sf_card.get("multiverse_id", None),
|
||||
"superTypes": super_types,
|
||||
"types": types,
|
||||
"subTypes": sub_types,
|
||||
}
|
||||
trice_cards.append(trice_card)
|
||||
if "//" in sf_card.get("name", ""):
|
||||
image = (
|
||||
sf_card["card_faces"][0]
|
||||
.get("image_uris", {})
|
||||
.get("normal", "")
|
||||
.rsplit("?", 1)[0],
|
||||
)
|
||||
else:
|
||||
image = sf_card.get("image_uris", {}).get("normal", "").rsplit("?", 1)[0]
|
||||
|
||||
try:
|
||||
trice_card = {
|
||||
"cmc": sf_card["cmc"],
|
||||
"names": sf_card.get("names", None),
|
||||
"mana_cost": sf_card.get("mana_cost", ""),
|
||||
"name": sf_card["name"],
|
||||
"number": sf_card["collector_number"],
|
||||
"rarity": sf_card["rarity"].replace("mythic", "mythic rare").title(),
|
||||
"text": sf_card.get("oracle_text", ""),
|
||||
"url": image,
|
||||
"type": sf_card.get("type_line", "Unknown").replace("—", "-"),
|
||||
"colorIdentity": sf_card.get("color_identity", None),
|
||||
"colors": sf_card.get("colors", []),
|
||||
"power": sf_card.get("power", None),
|
||||
"toughness": sf_card.get("toughness", None),
|
||||
"layout": sf_card["layout"].replace("normal", ""),
|
||||
"loyalty": sf_card.get("loyalty", None),
|
||||
"artist": sf_card.get("artist", ""),
|
||||
"flavor": sf_card.get("flavor_text", None),
|
||||
"multiverseId": sf_card.get("multiverse_id", None),
|
||||
"superTypes": super_types,
|
||||
"types": types,
|
||||
"subTypes": sub_types,
|
||||
}
|
||||
trice_cards.append(trice_card)
|
||||
except Exception:
|
||||
print(f"Unable to parse {sf_card.get('name')}")
|
||||
|
||||
return trice_cards
|
||||
|
||||
|
|
@ -192,7 +204,9 @@ def open_header(card_xml_file: IO[Any]) -> None:
|
|||
card_xml_file.write(
|
||||
"<cockatrice_carddatabase version='3'>\n"
|
||||
+ " <!--\n"
|
||||
+ " Created At: " + datetime.datetime.utcnow().strftime("%a, %b %d %Y, %H:%M:%S") + " (UTC)\n"
|
||||
+ " Created At: "
|
||||
+ datetime.datetime.utcnow().strftime("%a, %b %d %Y, %H:%M:%S")
|
||||
+ " (UTC)\n"
|
||||
+ " Created By: Magic-Spoiler project @ https://github.com/Cockatrice/Magic-Spoiler\n"
|
||||
+ " \n"
|
||||
+ " THIS FILE IS AUTOMATICALLY GENERATED & ALL EDITS WILL BE OVERRIDDEN.\n"
|
||||
|
|
@ -211,7 +225,7 @@ def fill_header_sets(card_xml_file: IO[Any], set_obj: Dict[str, str]) -> None:
|
|||
"<set>\n"
|
||||
"<name>" + set_obj["code"] + "</name>\n"
|
||||
"<longname>" + set_obj["name"] + "</longname>\n"
|
||||
"<settype>" + set_obj["set_type"].replace("_"," ").title() + "</settype>\n"
|
||||
"<settype>" + set_obj["set_type"].replace("_", " ").title() + "</settype>\n"
|
||||
"<releasedate>" + set_obj["released_at"] + "</releasedate>\n"
|
||||
"</set>\n"
|
||||
)
|
||||
|
|
@ -484,7 +498,11 @@ def write_set_xml(trice_dict: List[Dict[str, Any]], set_obj: Dict[str, str]) ->
|
|||
return
|
||||
|
||||
# Move new version to old location
|
||||
print("Changes detected, replacing {}.xml with updated version".format(set_obj["code"]))
|
||||
print(
|
||||
"Changes detected, replacing {}.xml with updated version".format(
|
||||
set_obj["code"]
|
||||
)
|
||||
)
|
||||
shutil.move(card_xml_file.name, old_xml_location)
|
||||
|
||||
|
||||
|
|
@ -506,13 +524,15 @@ def write_set_json(trice_dict: List[Dict[str, Any]], set_obj: Dict[str, str]) ->
|
|||
# If content didn't change, discard newest creation
|
||||
old_xml_location = str(OUTPUT_DIR.joinpath("{}.json".format(set_obj["code"])))
|
||||
if compare_json_content(str(output_file_path), old_xml_location):
|
||||
print(
|
||||
"No new data in {}.json, skipping replacement".format(set_obj["code"])
|
||||
)
|
||||
print("No new data in {}.json, skipping replacement".format(set_obj["code"]))
|
||||
return
|
||||
|
||||
# Move new version to old location
|
||||
print("Changes detected, replacing {}.json with updated version".format(set_obj["code"]))
|
||||
print(
|
||||
"Changes detected, replacing {}.json with updated version".format(
|
||||
set_obj["code"]
|
||||
)
|
||||
)
|
||||
shutil.move(str(output_file_path), old_xml_location)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user