From 445cb66282f3a2c51cd179eebbe1d0d14fe93237 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 2 Jul 2010 00:28:33 -0400 Subject: [PATCH] Wagic deck export --- mtg.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mtg.py b/mtg.py index 1dae979..952d61c 100644 --- a/mtg.py +++ b/mtg.py @@ -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()