Skip to content

Instantly share code, notes, and snippets.

@axlan
Last active February 11, 2022 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axlan/21faf9c28b40904662124d20ff365f2b to your computer and use it in GitHub Desktop.
Save axlan/21faf9c28b40904662124d20ff365f2b to your computer and use it in GitHub Desktop.
A script for generating a MPC Fill order from a list of local files.
import xml.etree.ElementTree as ET
import shutil
import os
CARD_FILE_OUT = 'order_HLB.xml'
TYPE = '.png'
IMAGE_SOURCE = 'C:/Users/feros/Documents/HLB_Deck/'
IMAGE_TARGET = 'C:/Users/feros/Documents/src/mpc-autofill/cards/'
OFFSET = 0
cards = [
"Witch’s Clinic",
"Abrade",
"Akroma, Angel of Fury",
"Arcbond",
"Ashling the Pilgrim",
"Banefire",
"Basilisk Collar",
"Blood Moon",
"Bonfire of the Damned",
"Braid of Fire",
"Brash Taunter",
"Burnished Hart",
"Caged Sun",
"Chandra, Awakened Inferno",
"Chandra, Flamecaller",
"Comet Storm",
"Darksteel Plate",
"Devil’s Play",
"Extraplanar Lens",
"Fall of the Titans",
"Fiery Emancipation",
"Furnace of Rath",
"Gauntlet of Power",
"Gratuitous Violence",
"Heartstone",
"Incendiary Command",
"Increasing Vengeance",
"Inferno Titan",
"Jaya’s Immolating Inferno",
"Koth of the Hammer",
"Lightning Bolt",
"Molten Rain",
"Myriad Landscape",
"Obsidian Fireheart",
"Primal Amulet",
"Pyromancer’s Goggles",
"Quest for Pure Flame",
"Red Sun’s Zenith",
"Repercussion",
"Reverberate",
"Ring of Valkas",
"Ruby Medallion",
"Ryusei, the Falling Star",
"Seething Song",
"Shadowspear",
"Shunt",
"Solemn Simulacrum",
"Spawn of Thraxes",
"Star of Extinction",
"Stigma Lasher",
"Stuffy Doll",
"Sword of Sinew and Steel",
"Tectonic Edge",
"Thaumatic Compass",
"Titan’s Revenge",
"Tormenting Voice",
"Urabrask the Hidden",
"Valakut, the Molten Pinnacle",
"Vandalblast",
"Volt Charge",
"Wild Ricochet",
]
card_back = 'card_back'
# Set this to True if using a card back ID copied from the site or another order
card_back_is_id = False
flips = [
("Primal Amulet", "Primal Wellspring"),
("Thaumatic Compass", "Spires of Orazca"),
]
def get_id(val):
return f'1{val:032}'
def copy_image(card, id):
#target_name = f'{IMAGE_TARGET}{card}({get_id(id)}){TYPE}'
target_name = f'{IMAGE_TARGET}{card}{TYPE}'
source_name = f'{IMAGE_SOURCE}{card}{TYPE}'
if not os.path.exists(target_name):
shutil.copyfile(source_name, target_name)
# Building the root element
# of the xml file
root = ET.Element("order")
# Building the sub root elements
# We don't add text since the value
# associated with subelement is a
# python dictionary
# <details>
# <quantity>553</quantity>
# <bracket>612</bracket>
# <stock>(S30) Standard Smooth</stock>
# <foil>false</foil>
# </details>
details = ET.SubElement(root, "details")
# Building multiple subelements with name options to hold different values
# Xml elements cannot hold integer values so we need to
# convert them to string
ET.SubElement(details, "quantity").text = str(len(cards))
ET.SubElement(details, "bracket").text = "612"
ET.SubElement(details, "stock").text = '(S30) Standard Smooth'
ET.SubElement(details, "foil").text = 'false'
# <fronts>
# <card>
# <id>1arwLgcWfcxnsJiRQLFZ3ilBBiGvqYJwn</id>
# <slots>0</slots>
# <name>Abrade.png</name>
# <query>abrade</query>
# </card>
id = OFFSET
fronts = ET.SubElement(root, "fronts")
for card in cards:
card_ele = ET.SubElement(fronts, "card")
ET.SubElement(card_ele, "id").text = get_id(id)
ET.SubElement(card_ele, "slot").text = str(id)
ET.SubElement(card_ele, "name").text = card + TYPE
ET.SubElement(card_ele, "query").text = card
copy_image(card, id)
id += 1
backs = ET.SubElement(root, "backs")
for card_pair in flips:
card = card_pair[1]
front = card_pair[0]
card_ele = ET.SubElement(backs, "card")
ET.SubElement(card_ele, "id").text = get_id(id)
ET.SubElement(card_ele, "slots").text = str(cards.index(front) + OFFSET)
ET.SubElement(card_ele, "name").text = card + TYPE
ET.SubElement(card_ele, "query").text = card
copy_image(card, id)
id += 1
if card_back_is_id:
ET.SubElement(root, "cardback").text = card_back
else:
ET.SubElement(root, "cardback").text = card_back + TYPE
copy_image(card_back, id)
# Building the tree of the xml
# elements using the root element
tree = ET.ElementTree(root)
# Writing the xml to output file
tree.write(CARD_FILE_OUT)
@axlan
Copy link
Author

axlan commented Feb 11, 2022

The one hack isthat the current MPC Autofill doesn't cache the card back, so in autofill.py I needed to change the line:

cardsinfo_cardback = [(order.cardback.text, "", "", "cardback")]

to

if '.' in order.cardback.text:
	cardsinfo_cardback = [("", "", order.cardback.text, "cardback")]
else:
	cardsinfo_cardback = [(order.cardback.text, "", "", "cardback")]

Alternatively you can set::

card_back = ID copied from the site or another order
card_back_is_id = True

in this script to download the card back from a Google Drive as normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment