Last active
August 29, 2019 15:56
-
-
Save petzku/b75476c95a2d8146710b845b3a43b8c5 to your computer and use it in GitHub Desktop.
Python script to reformat mtggoldfish decklists to "normal" text form
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
#!/usr/bin/env python3 | |
from typing import List | |
def goldfish_to_txt(lines: List[str], skip_headers=False) -> List[str]: | |
""" Takes a deck in mtggoldfish format and returns traditional text | |
Arguments: | |
lines -- each line is either a "header" or a decklist entry | |
skip_headers -- whether to skip header lines | |
Returns: | |
list of rows, effectively with mana cost and price removed | |
""" | |
decklist = [] | |
for line in lines: | |
if not line: | |
continue | |
if line[0].isalpha(): | |
# "header" (e.g. "Creature (15)"). possibly skip these? | |
if not skip_headers: | |
decklist.append(line.strip()) | |
else: | |
count, name, cost, price = line.split('\t') | |
decklist.append("{} {}".format(count, name)) | |
return decklist | |
if __name__ == "__main__": | |
import sys | |
# if we have args, assume it's a file to open | |
if len(sys.argv) > 1: | |
with open(sys.argv[1]) as fo: | |
src = fo.readlines() | |
else: | |
src = sys.stdin.readlines() | |
decklist = goldfish_to_txt(src) | |
print('\n'.join(decklist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reference, here's a sample MTGGoldfish decklist (as obtained by copy-pasting from the decklist section into Notepad++):
And corresponding output:
This is a format understood by most decklist parsers (ones I've come across, anyway).