Get ship type name from ESI

Closes #631
This commit is contained in:
Adarnof 2017-01-11 21:58:20 -05:00
parent 8360371ab7
commit e8915b84e5
2 changed files with 3 additions and 18 deletions

View File

@ -34,20 +34,3 @@ class srpManager:
return ship_type, ship_value
else:
raise ValueError("Invalid Kill ID")
@staticmethod
def get_ship_name(ship_type):
url = ("https://jetbalsa.com/api/json.php/invTypes/%s" % ship_type)
headers = {
'User-Agent': "%s Alliance Auth" % settings.DOMAIN,
'Content-Type': 'application/json',
}
r = requests.get(url, headers=headers)
result = r.json()
if result:
ship_name = result['typeName']
logger.debug("ship type %s determined to be %s" % (ship_type, ship_name))
return ship_name
else:
logger.debug("ship type %s is invalid" % ship_type)
raise ValueError("Cannot get ship name")

View File

@ -15,6 +15,7 @@ from services.managers.srp_manager import srpManager
from notifications import notify
from django.utils import timezone
from authentication.decorators import members_and_blues
from esi.clients import esi_client_factory
import uuid
import logging
@ -254,7 +255,8 @@ def srp_request_view(request, fleet_srp):
messages.error(request,
"Your SRP request Killmail link is invalid. Please make sure you are using zKillboard.")
return redirect("auth_srp_management_view")
srp_ship_name = srpManager.get_ship_name(srp_kill_data)
c = esi_client_factory()
srp_ship_name = c.Universe.get_universe_types_type_id(type_id=srp_kill_data).result()['type_name']
srp_request.srp_ship_name = srp_ship_name
kb_total_loss = ship_value
srp_request.kb_total_loss = kb_total_loss