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()