Skip to content

Instantly share code, notes, and snippets.

Last active February 11, 2022 08:53
What would you like to do?
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/'
cards = [
"Witch’s Clinic",
"Akroma, Angel of Fury",
"Ashling the Pilgrim",
"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",
"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",
"Ring of Valkas",
"Ruby Medallion",
"Ryusei, the Falling Star",
"Seething Song",
"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",
"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>
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
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
Copy link

axlan commented Feb 11, 2022

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

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


if '.' in order.cardback.text:
	cardsinfo_cardback = [("", "", order.cardback.text, "cardback")]
	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