mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-11 21:40:17 +02:00
Merge branch 'srp_api_fix' into 'master'
Update SRP module for zKill API changes. See merge request allianceauth/allianceauth!1102
This commit is contained in:
commit
73403b98df
@ -1,9 +1,15 @@
|
|||||||
from allianceauth import NAME
|
from allianceauth import NAME
|
||||||
|
from esi.clients import esi_client_factory
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
SWAGGER_SPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'swagger.json')
|
||||||
|
"""
|
||||||
|
Swagger Operations:
|
||||||
|
get_killmails_killmail_id_killmail_hash
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class SRPManager:
|
class SRPManager:
|
||||||
@ -26,12 +32,20 @@ class SRPManager:
|
|||||||
r = requests.get(url, headers=headers)
|
r = requests.get(url, headers=headers)
|
||||||
result = r.json()[0]
|
result = r.json()[0]
|
||||||
if result:
|
if result:
|
||||||
ship_type = result['victim']['ship_type_id']
|
killmail_id = result['killmail_id']
|
||||||
|
killmail_hash = result['zkb']['hash']
|
||||||
|
c = esi_client_factory(spec_file=SWAGGER_SPEC_PATH)
|
||||||
|
km = c.Killmails.get_killmails_killmail_id_killmail_hash(killmail_id=killmail_id,
|
||||||
|
killmail_hash=killmail_hash).result()
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid Kill ID")
|
||||||
|
if km:
|
||||||
|
ship_type = km['victim']['ship_type_id']
|
||||||
logger.debug("Ship type for kill ID %s is %s" % (kill_id, ship_type))
|
logger.debug("Ship type for kill ID %s is %s" % (kill_id, ship_type))
|
||||||
ship_value = result['zkb']['totalValue']
|
ship_value = result['zkb']['totalValue']
|
||||||
logger.debug("Total loss value for kill id %s is %s" % (kill_id, ship_value))
|
logger.debug("Total loss value for kill id %s is %s" % (kill_id, ship_value))
|
||||||
victim_id = result['victim']['character_id']
|
victim_id = km['victim']['character_id']
|
||||||
return ship_type, ship_value, victim_id
|
return ship_type, ship_value, victim_id
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid Kill ID")
|
raise ValueError("Invalid Kill ID or Hash.")
|
||||||
|
|
||||||
|
1
allianceauth/srp/swagger.json
Normal file
1
allianceauth/srp/swagger.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user