Committing the import utility so far

Eventually needs to belong somewhere
This commit is contained in:
Correl Roush 2010-09-16 14:12:31 -04:00
parent 4c9e0ca626
commit 0e6f05bac5

25
importutil.py Normal file
View file

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