mtg-web/importutil.py
Correl Roush 0e6f05bac5 Committing the import utility so far
Eventually needs to belong somewhere
2010-09-16 14:12:31 -04:00

25 lines
807 B
Python

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