Last active
May 10, 2025 01:44
-
-
Save J-Priebe/91322b682ebd625ffccc44ab9a595429 to your computer and use it in GitHub Desktop.
Transform Moxfield Export format to printingproxies-friendly format
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
| """ | |
| Grab card GUIDs from scryfall to transform moxfield format into printing proxies format. | |
| Allows you to preserve the desired card art and foil status. | |
| Example Input: | |
| 1 Karador, Ghost Chieftain (2X2) 238 *F* | |
| 1 Aftermath Analyst (MKM) 148 | |
| 1 Altar of Dementia (BRR) 3 | |
| 1 Ancient Tomb (UMA) 236 | |
| Example Output: | |
| 1 Karador, Ghost Chieftain FOIL [6200ac79-b166-43d0-9a0b-5b547625ed57] | |
| 1 Aftermath Analyst [1c1aa6f8-2d34-4f4b-9184-0eab2e4745f7] | |
| 1 Altar of Dementia [8bab577a-4d2b-4b52-a861-1a43fdaa3f97] | |
| 1 Ancient Tomb [bd3d4b4b-cf31-4f89-8140-9650edb03c7b] | |
| """ | |
| import requests | |
| from urllib.parse import quote | |
| from time import sleep | |
| def parse_moxfield_card_data(card_str): | |
| """ | |
| Extract quantity, card name, set code, and foil status from a Moxfield card string. | |
| E.g., | |
| 1 Karador, Ghost Chieftain (2X2) 238 *F* | |
| -> 1, "Karador, Ghost Chieftain", "2X2", True | |
| """ | |
| quantity_str, rest = card_str.split(" ", 1) | |
| quantity = int(quantity_str) | |
| card_name, rest = rest.split(" (", 1) | |
| card_name = card_name.strip() | |
| set_code, rest = rest.split(") ", 1) | |
| is_foil = "*F*" in rest | |
| return quantity, card_name, set_code.strip(), is_foil | |
| def fetch_card_data(card_name, set_code): | |
| """ | |
| Fetch card data from Scryfall API. | |
| """ | |
| url = f"https://api.scryfall.com/cards/named?exact={quote(card_name)}&set={quote(set_code)}" | |
| response = requests.get(url) | |
| response.raise_for_status() | |
| return response.json() | |
| def transform_moxfield_to_printing_proxies(moxfield_export_str): | |
| """ | |
| Transform Moxfield card strings to Printing Proxies format. | |
| """ | |
| lines = moxfield_export_str.strip().splitlines() | |
| transformed_lines = [] | |
| errors = [] | |
| for line in lines: | |
| try: | |
| quantity, card_name, set_code, is_foil = parse_moxfield_card_data(line) | |
| card_data = fetch_card_data(card_name, set_code) | |
| # 2 Karador, Ghost Chieftain FOIL [104e146a-6acd-4371-a91d-b47aba75a41e] | |
| pp_format = ( | |
| f"{quantity} {card_name}{' FOIL ' if is_foil else ' '}" | |
| f"[{card_data['id']}]" | |
| ) | |
| print(f"Transformed: {line} -> {pp_format}") | |
| except Exception: | |
| print(f"Error processing card: {line}") | |
| errors.append(line) | |
| else: | |
| transformed_lines.append(pp_format) | |
| # be nice to scryfall | |
| sleep(0.5) | |
| print("\n-----DONE-----\n") | |
| for line in transformed_lines: | |
| print(line) | |
| return transformed_lines, errors | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment