Skip to content

@borensoren /createmagicdeck.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Creates MTG deck
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.