Wagic deck export

This commit is contained in:
Correl Roush 2010-07-02 00:28:33 -04:00
parent 8f38aaf09b
commit 445cb66282

15
mtg.py
View file

@ -295,3 +295,18 @@ class Deck(CardList):
# TODO: The database should log an error
continue
self.extend(card * count)
def exportWagic(self, filename, name=None):
cards = {}
for card in self:
cards[card] = cards[card] + 1 if card in cards.keys() else 1
lines = [
'#NAME:{0}\n'.format(name if name else filename),
'#DESC: Exported deck\n\n',
]
for card, count in cards.iteritems():
sets = card.sets
line = '{0} ({1}) *{2}\n'.format(card.name, card.sets[-1], count)
lines.append(line)
with open(filename, 'w') as f:
f.writelines(lines)
f.close()