Committing the import utility so far
Eventually needs to belong somewhere
This commit is contained in:
parent
4c9e0ca626
commit
0e6f05bac5
1 changed files with 25 additions and 0 deletions
25
importutil.py
Normal file
25
importutil.py
Normal 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()
|
Loading…
Reference in a new issue