mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-17 19:59:29 +00:00
Now pulls in more information from the character API.
This commit is contained in:
@@ -56,30 +56,75 @@ def import_eve_account(api_key, user_id):
|
|||||||
|
|
||||||
for node in characters_node_children:
|
for node in characters_node_children:
|
||||||
try:
|
try:
|
||||||
|
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.
|
# Get this first, as it's safe.
|
||||||
corporation_id = node.getAttribute('corporationID')
|
corporation_id = values['corporationID']
|
||||||
corp, created = EVEPlayerCorporation.objects.get_or_create(id=corporation_id)
|
corp, created = EVEPlayerCorporation.objects.get_or_create(id=corporation_id)
|
||||||
if not corp.name:
|
if not corp.name:
|
||||||
try:
|
try:
|
||||||
corp.query_and_update_corp()
|
corp.query_and_update_corp()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# Do this last, since the things we retrieved above are used
|
|
||||||
# on the EVEPlayerCharacter object's fields.
|
name = values['name']
|
||||||
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.
|
# Save these for last to keep the save count low.
|
||||||
pchar.name = name
|
pchar.name = name
|
||||||
pchar.corporation = corp
|
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.api_last_updated = datetime.utcnow()
|
||||||
pchar.save()
|
pchar.save()
|
||||||
account.characters.add(pchar)
|
|
||||||
except AttributeError:
|
|
||||||
# This must be a Text node, ignore it.
|
|
||||||
continue
|
|
||||||
|
|
||||||
return account
|
return pchar
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -13,3 +13,38 @@ API_STATUS_CHOICES = (
|
|||||||
(API_STATUS_AUTH_ERROR, 'Auth Error'),
|
(API_STATUS_AUTH_ERROR, 'Auth Error'),
|
||||||
(API_STATUS_OTHER_ERROR, 'Other Error'),
|
(API_STATUS_OTHER_ERROR, 'Other Error'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
API_GENDER_CHOICES = (
|
||||||
|
(1, 'Male'),
|
||||||
|
(2, 'Female'),
|
||||||
|
)
|
||||||
|
|
||||||
|
API_RACES_CHOICES = (
|
||||||
|
(1, 'Sebiestor'),
|
||||||
|
(2, 'Vherokior'),
|
||||||
|
(3, 'Brutor'),
|
||||||
|
(4, 'Intaki'),
|
||||||
|
(5, 'Gallente'),
|
||||||
|
(6, 'Jin-Mei'),
|
||||||
|
(7, 'Civire'),
|
||||||
|
(8, 'Deteis'),
|
||||||
|
(9, 'Achura'),
|
||||||
|
(10, 'Amarr'),
|
||||||
|
(11, 'Khanid'),
|
||||||
|
(12, 'Ni-Kunni'),
|
||||||
|
)
|
||||||
|
|
||||||
|
API_RACES = {
|
||||||
|
'Sebiestor': 1,
|
||||||
|
'Vherokior': 2,
|
||||||
|
'Brutor': 3,
|
||||||
|
'Intaki': 4,
|
||||||
|
'Gallente': 5,
|
||||||
|
'Jin-Mei': 6,
|
||||||
|
'Civire': 7,
|
||||||
|
'Deteis': 8,
|
||||||
|
'Achura': 9,
|
||||||
|
'Amarr': 10,
|
||||||
|
'Khanid': 11,
|
||||||
|
'Ni-Kunni': 12,
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from django.db import models
|
|||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from eve_proxy.models import CachedDocument
|
from eve_proxy.models import CachedDocument
|
||||||
from eve_api.managers import EVEPlayerCorporationManager, EVEPlayerAllianceManager, EVEPlayerCharacterManager
|
from eve_api.managers import EVEPlayerCorporationManager, EVEPlayerAllianceManager, EVEPlayerCharacterManager
|
||||||
from eve_api.app_defines import API_STATUS_CHOICES, API_STATUS_PENDING
|
from eve_api.app_defines import API_STATUS_CHOICES, API_STATUS_PENDING, API_RACES_CHOICES, API_GENDER_CHOICES
|
||||||
|
|
||||||
class EVEAPIModel(models.Model):
|
class EVEAPIModel(models.Model):
|
||||||
"""
|
"""
|
||||||
@@ -64,10 +64,8 @@ class EVEPlayerCharacter(EVEAPIModel):
|
|||||||
"""
|
"""
|
||||||
name = models.CharField(max_length=255, blank=True, null=False)
|
name = models.CharField(max_length=255, blank=True, null=False)
|
||||||
corporation = models.ForeignKey('EVEPlayerCorporation', blank=True, null=True)
|
corporation = models.ForeignKey('EVEPlayerCorporation', blank=True, null=True)
|
||||||
# TODO: Choices field
|
race = models.IntegerField(blank=True, null=True, choices=API_RACES_CHOICES)
|
||||||
race = models.IntegerField(blank=True, null=True)
|
gender = models.IntegerField(blank=True, null=True, choices=API_GENDER_CHOICES)
|
||||||
# TODO: Choices field
|
|
||||||
gender = models.IntegerField(blank=True, null=True)
|
|
||||||
balance = models.FloatField("Account Balance", blank=True, null=True)
|
balance = models.FloatField("Account Balance", blank=True, null=True)
|
||||||
attrib_intelligence = models.IntegerField("Intelligence", blank=True,
|
attrib_intelligence = models.IntegerField("Intelligence", blank=True,
|
||||||
null=True)
|
null=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user