Created
October 18, 2022 01:36
-
-
Save rsullivan00/df968d764101a84244b4b1a06caecf79 to your computer and use it in GitHub Desktop.
Import a directory of images into mpcfill
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 os | |
import xml.etree.ElementTree as ET | |
# This script generates an [MPC Fill](https://github.com/chilli-axe/mpc-autofill) order | |
# file from directories of PNGs and prints the order XML to stdout. | |
# | |
# Usage: | |
# 1. Edit my paths/directory names | |
# 2. Edit the contents of order below, especially `quantity` (must match front image count) and `cardback`. | |
# 2. Run `python write_cards_xml.py > cards.xml` | |
# 3. Open `cards.xml` in a text editor and replace all "TODO" slots with the corresponding front-card numbers | |
# 4. Put `cards.xml` the same directory as `autofill-windows.exe` or similar, and run the autofiller | |
currentdir = 'C:\Users\Rick\Desktop\cube' | |
frontfiles = [] | |
frontsdirpath = 'Black Bordered Edition-20221016T223549Z-001/Black Bordered Edition' | |
for filename in os.listdir(frontsdirpath): | |
if not filename.endswith('.png'): | |
continue | |
frontfiles.append(filename) | |
backfiles = [] | |
backsdirpaths = [ | |
'Black Bordered Edition-20221016T223549Z-001/Black Bordered Edition/Customs', | |
'Black Bordered Edition-20221016T223549Z-001/Black Bordered Edition/DFC B' | |
] | |
for backsdirpath in backsdirpaths: | |
for filename in os.listdir(backsdirpath): | |
if not filename.endswith('.png'): | |
continue | |
backfiles.append((filename, backsdirpath)) | |
# Cards look like | |
# <card> | |
# <id>10CNN72lnTzYL6JOtRYNr4E9G7ENJMcl9</id> | |
# <slots>0</slots> | |
# <name>Lightning Bolt.png</name> | |
# <query>lightning bolt</query> | |
# </card> | |
order = ET.fromstring(""" | |
<order> | |
<details> | |
<quantity>540</quantity> | |
<bracket>18</bracket> | |
<stock>(S33) Superior Smooth</stock> | |
<foil>false</foil> | |
</details> | |
<fronts> | |
</fronts> | |
<backs> | |
</backs> | |
<cardback>1B6Zi82YPhjYlqU2c7BBGK--pdducb_xO</cardback> | |
</order> | |
""") | |
fronts = order.find("fronts") | |
slot = 0 | |
for cardfile in frontfiles: | |
query = cardfile.split(".")[0] | |
card = ET.SubElement(fronts, "card") | |
ET.SubElement(card, "id").text = os.path.join(currentdir, frontsdirpath, cardfile) | |
ET.SubElement(card, "slots").text = "{}".format(slot) | |
ET.SubElement(card, "query").text = query | |
slot += 1 | |
backs = order.find("backs") | |
for (cardfile, dirpath) in backfiles: | |
query = cardfile.split(".")[0] | |
card = ET.SubElement(backs, "card") | |
ET.SubElement(card, "id").text = os.path.join(currentdir, dirpath, cardfile) | |
ET.SubElement(card, "slots").text = "TODO" | |
ET.SubElement(card, "query").text = query | |
ET.dump(order) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment