diff --git a/eve_api/admin.py b/eve_api/admin.py index 17363cc..b068eca 100644 --- a/eve_api/admin.py +++ b/eve_api/admin.py @@ -8,12 +8,7 @@ from eve_api.api_puller.accounts import import_eve_account def account_api_update(modeladmin, request, queryset): for obj in queryset: - try: - import_eve_account(obj.api_key, obj.api_user_id) - obj.api_status = 1 - except APIAuthException: - obj.api_status = 2 - obj.save() + import_eve_account(obj.api_key, obj.api_user_id) account_api_update.short_description = "Update account from the EVE API" diff --git a/eve_api/api_puller/accounts.py b/eve_api/api_puller/accounts.py index 5a3c8af..8104431 100755 --- a/eve_api/api_puller/accounts.py +++ b/eve_api/api_puller/accounts.py @@ -23,9 +23,27 @@ def import_eve_account(api_key, user_id): Imports an account from the API into the EVEAccount model. """ auth_params = {'userID': user_id, 'apiKey': api_key} - account_doc = CachedDocument.objects.api_query('/account/Characters.xml.aspx', + + try: + account_doc = CachedDocument.objects.api_query('/account/Characters.xml.aspx', params=auth_params, no_cache=False) + except APIAuthException: + try: + account = EVEAccount.objects.get(id=user_id) + except EVEAccount.DoesNotExist: + return + if api_key == account.api_key: + account.api_status = API_STATUS_AUTH_ERROR + account.api_last_updated = datetime.utcnow() + account.save() + return + except APINoUserIDException: + try: + account = EVEAccount.objects.get(id=user_id) + account.delete() + except EVEAccount.DoesNotExist: + return dom = minidom.parseString(account_doc.body.encode('utf-8')) @@ -52,8 +70,6 @@ def import_eve_account(api_key, user_id): account.api_key = api_key account.api_user_id = user_id account.api_status = API_STATUS_OK - account.api_last_updated = datetime.utcnow() - account.save() for node in characters_node_children: try: @@ -63,6 +79,9 @@ def import_eve_account(api_key, user_id): except AttributeError: # This must be a Text node, ignore it. continue + + account.api_last_updated = datetime.utcnow() + account.save() return account def import_eve_character(api_key, user_id, character_id): diff --git a/eve_api/cron.py b/eve_api/cron.py index 26f70dc..2713072 100644 --- a/eve_api/cron.py +++ b/eve_api/cron.py @@ -24,13 +24,7 @@ class UpdateAPIs(): if not acc.user: acc.delete() continue - try: - eve_api.api_puller.accounts.import_eve_account(acc.api_key, acc.api_user_id) - acc.api_status = 1 - except APIAuthException: - acc.api_status = 2 - - acc.save() + eve_api.api_puller.accounts.import_eve_account(acc.api_key, acc.api_user_id) if self.settings['update_corp']: for corp in EVEPlayerCorporation.objects.all():