Now pulls in more information from the character API.

This commit is contained in:
2010-04-02 23:02:45 +01:00
parent 9c6272d4f5
commit 1637318522
3 changed files with 104 additions and 26 deletions

View File

@@ -56,31 +56,76 @@ def import_eve_account(api_key, user_id):
for node in characters_node_children:
try:
# Get this first, as it's safe.
corporation_id = node.getAttribute('corporationID')
corp, created = EVEPlayerCorporation.objects.get_or_create(id=corporation_id)
if not corp.name:
try:
corp.query_and_update_corp()
except:
pass
# Do this last, since the things we retrieved above are used
# on the EVEPlayerCharacter object's fields.
character_id = node.getAttribute('characterID')
pchar, created = EVEPlayerCharacter.objects.get_or_create(id=character_id)
name = node.getAttribute('name')
# Save these for last to keep the save count low.
pchar.name = name
pchar.corporation = corp
pchar.api_last_updated = datetime.utcnow()
pchar.save()
account.characters.add(pchar)
char = import_eve_character(api_key, user_id, node.getAttribute('characterID'))
if char:
account.characters.add(char)
except AttributeError:
# This must be a Text node, ignore it.
continue
return account
def import_eve_character(api_key, user_id, character_id):
auth_params = {'userID': user_id, 'apiKey': api_key, 'characterID': character_id }
char_doc = CachedDocument.objects.api_query('/char/CharacterSheet.xml.aspx',
params=auth_params,
no_cache=False)
dom = minidom.parseString(char_doc.body)
if dom.getElementsByTagName('error'):
return
nodes = dom.getElementsByTagName('result')[0].childNodes
pchar, created = EVEPlayerCharacter.objects.get_or_create(id=character_id)
values = {}
for node in nodes:
if node.nodeType == 1:
node.normalize()
if len(node.childNodes) == 1:
values[node.tagName] = node.childNodes[0].nodeValue
else:
if node.tagName == "rowset":
continue
nv = {}
for nd in node.childNodes:
if nd.nodeType == 1:
nv[nd.tagName] = nd.childNodes[0].nodeValue
values[node.tagName] = nv
# Get this first, as it's safe.
corporation_id = values['corporationID']
corp, created = EVEPlayerCorporation.objects.get_or_create(id=corporation_id)
if not corp.name:
try:
corp.query_and_update_corp()
except:
pass
name = values['name']
# Save these for last to keep the save count low.
pchar.name = name
pchar.corporation = corp
pchar.balance = values['balance']
pchar.attrib_intelligence = values['attributes']['intelligence']
pchar.attrib_charisma = values['attributes']['charisma']
pchar.attrib_perception = values['attributes']['perception']
pchar.attrib_willpower = values['attributes']['willpower']
pchar.attrib_memory = values['attributes']['memory']
if values['gender'] == 'Male':
pchar.gender = 1
else:
pchar.gender = 2
pchar.race = API_RACES[values['race']]
pchar.api_last_updated = datetime.utcnow()
pchar.save()
return pchar
if __name__ == "__main__":
"""
Test import.