mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-15 15:22:17 +00:00
Added further error checking code to the corporate details import
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
|
||||||
@@ -6,23 +7,51 @@ from eve_proxy.models import CachedDocument
|
|||||||
from eve_api.models import EVEPlayerCorporation, EVEPlayerCharacter, EVEPlayerAlliance
|
from eve_api.models import EVEPlayerCorporation, EVEPlayerCharacter, EVEPlayerAlliance
|
||||||
from eve_api.utils import basic_xml_parse_doc
|
from eve_api.utils import basic_xml_parse_doc
|
||||||
from eve_api.tasks.character import import_eve_character
|
from eve_api.tasks.character import import_eve_character
|
||||||
|
from eve_api.api_exceptions import APIAccessException
|
||||||
|
|
||||||
@task(ignore_result=True)
|
@task(ignore_result=True)
|
||||||
def import_corp_details(corp_id):
|
def import_corp_details(corp_id, callback=None, **kwargs):
|
||||||
import_corp_details_func(corp_id)
|
log = import_corp_details.get_logger()
|
||||||
|
try:
|
||||||
|
corp = import_corp_details_func(corp_id, log)
|
||||||
|
except APIAccessException, exc:
|
||||||
|
log.error('Error importing corporation - queueing for retry')
|
||||||
|
import_corp_details.retry(args=[corp_id, callback], exc=exc, kwargs=kwargs)
|
||||||
|
|
||||||
|
if callback:
|
||||||
|
subtask(callback).delay(corporation=corp.id)
|
||||||
|
else:
|
||||||
|
return corp
|
||||||
|
|
||||||
|
|
||||||
@task()
|
@task()
|
||||||
def import_corp_details_result(corp_id):
|
def import_corp_details_result(corp_id, callback=None):
|
||||||
return import_corp_details_func(corp_id)
|
log = import_corp_details_result.get_logger()
|
||||||
|
try:
|
||||||
|
corp = import_corp_details_func(corp_id, log)
|
||||||
|
except APIAccessException, exc:
|
||||||
|
log.error('Error importing corporation')
|
||||||
|
return none
|
||||||
|
|
||||||
|
if callback:
|
||||||
|
subtask(callback).delay(corporation=corp.id)
|
||||||
|
else:
|
||||||
|
return corp
|
||||||
|
|
||||||
|
|
||||||
def import_corp_details_func(corp_id):
|
def import_corp_details_func(corp_id, log=logging.getLogger(__name__)):
|
||||||
|
|
||||||
corpobj, created = EVEPlayerCorporation.objects.get_or_create(id=corp_id)
|
corpobj, created = EVEPlayerCorporation.objects.get_or_create(id=corp_id)
|
||||||
if created or not corpobj.api_last_updated or corpobj.api_last_updated < (datetime.utcnow() - timedelta(hours=12)):
|
if created or not corpobj.api_last_updated or corpobj.api_last_updated < (datetime.utcnow() - timedelta(hours=12)):
|
||||||
|
|
||||||
doc = CachedDocument.objects.api_query('/corp/CorporationSheet.xml.aspx', {'corporationID': corp_id})
|
doc = CachedDocument.objects.api_query('/corp/CorporationSheet.xml.aspx', {'corporationID': corp_id})
|
||||||
d = basic_xml_parse_doc(doc)['eveapi']['result']
|
d = basic_xml_parse_doc(doc)['eveapi']
|
||||||
|
|
||||||
|
if 'error' in d:
|
||||||
|
log.error("Error importing Corp %s: %s" % (corp_id, d['error']))
|
||||||
|
raise APIAccessException
|
||||||
|
else:
|
||||||
|
d = d['result']
|
||||||
|
|
||||||
tag_mappings = (
|
tag_mappings = (
|
||||||
('corporationName', 'name'),
|
('corporationName', 'name'),
|
||||||
|
|||||||
Reference in New Issue
Block a user