Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Creates MTG deck

View createmagicdeck.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import re
 
CARDLIST = open('deck','r')
 
"""
opens a text file with a list of cards and quantities formatted as such:
22 ISLAND
47 ORNITHOPTER etc..
"""
 
raw_deck = [] ##this list will hold the raw quantity/card name data eg: 22 ISLAND
 
deck = [] ##this will be the finalized version of the deck with 47 instances of ornithopter
 
for i in CARDLIST: ##append quantity/cardname to raw deck sans newline characters
raw_deck.append(i[0:-1])
 
def find_card_quantity(raw_deck,deck,card): ##function that separates quantity from card name
re.search(([\d]+)\s([\w\s]+),raw_deck) ##and appends that to the deck list
card_quantity = match.group(1)
card_name = match.group(3)
for i in card_quantity:
deck.append(card_name)
 
for card in raw_deck: ##cycles through raw_deck, cleaning up the format
find_card_quantity(raw_deck,deck,card) ##and adding the correct quantities to the finished deck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.