Skip to content

Instantly share code, notes, and snippets.

@petzku
Last active August 29, 2019 15:56
Show Gist options
  • Save petzku/b75476c95a2d8146710b845b3a43b8c5 to your computer and use it in GitHub Desktop.
Save petzku/b75476c95a2d8146710b845b3a43b8c5 to your computer and use it in GitHub Desktop.
Python script to reformat mtggoldfish decklists to "normal" text form
#!/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))
@petzku
Copy link
Author

petzku commented Aug 29, 2019

For reference, here's a sample MTGGoldfish decklist (as obtained by copy-pasting from the decklist section into Notepad++):

Creatures (25)
4	Knight of the Ebon Legion	b	1.56
4	Skymarcher Aspirant	w	0.08
4	Vicious Conquistador	b	0.08
4	Adanto Vanguard	1w	0.12
4	Legion Lieutenant	wb	0.08
2	Sanctum Seeker	2bb	0.04
2	Champion of Dusk	3bb	0.04
1	Vona, Butcher of Magan	3wb	0.22
Planeswalkers (4)
4	Sorin, Imperious Bloodlord	2b	65.36
Spells (5)
2	Cast Down	1b	0.08
2	Legion's End	1b	1.40
1	Mortify	1wb	0.01
Enchantments (4)
4	Legion's Landing	w	0.44
Lands (22)
4	Godless Shrine		4.28
4	Isolated Chapel		0.12
6	Plains		0.00
7	Swamp		0.00
1	Unclaimed Territory		0.04
Sideboard (15)
4	Duress	b	0.08
1	Cast Down	1b	0.04
1	Despark	wb	0.01
2	Legion's End	1b	1.40
3	Noxious Grasp	1b	0.12
1	Ashiok, Dream Render	1ubub	0.34
2	Gideon Blackblade	1ww	5.62
1	Vona, Butcher of Magan	3wb	0.22

And corresponding output:

Creatures (25)
4 Knight of the Ebon Legion
4 Skymarcher Aspirant
4 Vicious Conquistador
4 Adanto Vanguard
4 Legion Lieutenant
2 Sanctum Seeker
2 Champion of Dusk
1 Vona, Butcher of Magan
Planeswalkers (4)
4 Sorin, Imperious Bloodlord
Spells (5)
2 Cast Down
2 Legion's End
1 Mortify
Enchantments (4)
4 Legion's Landing
Lands (22)
4 Godless Shrine
4 Isolated Chapel
6 Plains
7 Swamp
1 Unclaimed Territory
Sideboard (15)
4 Duress
1 Cast Down
1 Despark
2 Legion's End
3 Noxious Grasp
1 Ashiok, Dream Render
2 Gideon Blackblade
1 Vona, Butcher of Magan

This is a format understood by most decklist parsers (ones I've come across, anyway).

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