From 0e6f05bac5875c87c45c459bf9bf8e5f039d0a36 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Thu, 16 Sep 2010 14:12:31 -0400 Subject: [PATCH] Committing the import utility so far Eventually needs to belong somewhere --- importutil.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 importutil.py diff --git a/importutil.py b/importutil.py new file mode 100644 index 0000000..831e2e0 --- /dev/null +++ b/importutil.py @@ -0,0 +1,25 @@ +from mtgweb.lib.mtg import database +from mtgweb.analyzer.models import Card, CardType, Attribute + +def doimport(): + db = database.TextDB('lib/mtg/db.txt') + for c in db.findCard(): + print c + try: + card_type = CardType.objects.get(name=c.type) + except: + card_type = CardType.objects.create(name=c.type) + card = Card(name=c.name, type=card_type,cost=c.cost, power=c.power, toughness=c.toughness) + + card.converted_cost = c.cost.converted() + card.text = "\n".join(c.text) + card.save() + attributes = [] + for a in c.attributes: + try: + attr = Attribute.objects.get(name=a) + except: + attr = Attribute.objects.create(name=a) + card.attributes.add(attr) + +doimport()