From 7aa1a2f3368c096cc1d093ed53a5d5e3983fba8f Mon Sep 17 00:00:00 2001 From: colcrunch Date: Sun, 7 Oct 2018 22:08:03 +0000 Subject: [PATCH] Update SRP module for zKill API changes. --- allianceauth/srp/managers.py | 22 ++++++++++++++++++---- allianceauth/srp/swagger.json | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 allianceauth/srp/swagger.json diff --git a/allianceauth/srp/managers.py b/allianceauth/srp/managers.py index bdb9911a..8dfbe81a 100644 --- a/allianceauth/srp/managers.py +++ b/allianceauth/srp/managers.py @@ -1,9 +1,15 @@ from allianceauth import NAME - +from esi.clients import esi_client_factory import requests import logging +import os 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: @@ -26,12 +32,20 @@ class SRPManager: r = requests.get(url, headers=headers) result = r.json()[0] 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)) ship_value = result['zkb']['totalValue'] 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 else: - raise ValueError("Invalid Kill ID") + raise ValueError("Invalid Kill ID or Hash.") diff --git a/allianceauth/srp/swagger.json b/allianceauth/srp/swagger.json new file mode 100644 index 00000000..311b702f --- /dev/null +++ b/allianceauth/srp/swagger.json @@ -0,0 +1 @@ +{"consumes":["application/json"],"definitions":{"bad_request":{"description":"Bad request model","properties":{"error":{"description":"Bad request message","type":"string"}},"required":["error"],"title":"Bad request","type":"object"},"error_limited":{"description":"Error limited model","properties":{"error":{"description":"Error limited message","type":"string"}},"required":["error"],"title":"Error limited","type":"object"},"forbidden":{"description":"Forbidden model","properties":{"error":{"description":"Forbidden message","type":"string"},"sso_status":{"description":"status code received from SSO","type":"integer"}},"required":["error"],"title":"Forbidden","type":"object"},"gateway_timeout":{"description":"Gateway timeout model","properties":{"error":{"description":"Gateway timeout message","type":"string"},"timeout":{"description":"number of seconds the request was given","type":"integer"}},"required":["error"],"title":"Gateway timeout","type":"object"},"internal_server_error":{"description":"Internal server error model","properties":{"error":{"description":"Internal server error message","type":"string"}},"required":["error"],"title":"Internal server error","type":"object"},"service_unavailable":{"description":"Service unavailable model","properties":{"error":{"description":"Service unavailable message","type":"string"}},"required":["error"],"title":"Service unavailable","type":"object"},"unauthorized":{"description":"Unauthorized model","properties":{"error":{"description":"Unauthorized message","type":"string"}},"required":["error"],"title":"Unauthorized","type":"object"}},"host":"esi.evetech.net","info":{"description":"An OpenAPI for EVE Online","title":"EVE Swagger Interface","version":"0.8.6"},"parameters":{"Accept-Language":{"default":"en-us","description":"Language to use in the response","enum":["de","en-us","fr","ja","ru","zh"],"in":"header","name":"Accept-Language","type":"string"},"If-None-Match":{"description":"ETag from a previous request. A 304 will be returned if this matches the current ETag","in":"header","name":"If-None-Match","type":"string"},"alliance_id":{"description":"An EVE alliance ID","format":"int32","in":"path","minimum":1,"name":"alliance_id","required":true,"type":"integer"},"character_id":{"description":"An EVE character ID","format":"int32","in":"path","minimum":1,"name":"character_id","required":true,"type":"integer"},"corporation_id":{"description":"An EVE corporation ID","format":"int32","in":"path","minimum":1,"name":"corporation_id","required":true,"type":"integer"},"datasource":{"default":"tranquility","description":"The server name you would like data from","enum":["tranquility","singularity"],"in":"query","name":"datasource","type":"string"},"language":{"default":"en-us","description":"Language to use in the response, takes precedence over Accept-Language","enum":["de","en-us","fr","ja","ru","zh"],"in":"query","name":"language","type":"string"},"page":{"default":1,"description":"Which page of results to return","format":"int32","in":"query","minimum":1,"name":"page","type":"integer"},"token":{"description":"Access token to use if unable to set a header","in":"query","name":"token","type":"string"}},"paths":{"/v1/killmails/{killmail_id}/{killmail_hash}/":{"get":{"description":"Return a single killmail from its ID and hash\n\n---\n\nThis route is cached for up to 1209600 seconds","operationId":"get_killmails_killmail_id_killmail_hash","parameters":[{"$ref":"#/parameters/datasource"},{"$ref":"#/parameters/If-None-Match"},{"description":"The killmail hash for verification","in":"path","name":"killmail_hash","required":true,"type":"string"},{"description":"The killmail ID to be queried","format":"int32","in":"path","name":"killmail_id","required":true,"type":"integer"}],"responses":{"200":{"description":"A killmail","examples":{"application/json":{"attackers":[{"character_id":95810944,"corporation_id":1000179,"damage_done":5745,"faction_id":500003,"final_blow":true,"security_status":-0.3,"ship_type_id":17841,"weapon_type_id":3074}],"killmail_id":56733821,"killmail_time":"2016-10-22T17:13:36Z","solar_system_id":30002976,"victim":{"alliance_id":621338554,"character_id":92796241,"corporation_id":841363671,"damage_taken":5745,"items":[{"flag":20,"item_type_id":5973,"quantity_dropped":1,"singleton":0}],"position":{"x":452186600569.4748,"y":146704961490.90222,"z":109514596532.54477},"ship_type_id":17812}}},"headers":{"Cache-Control":{"description":"The caching mechanism used","type":"string"},"ETag":{"description":"RFC7232 compliant entity tag","type":"string"},"Expires":{"description":"RFC7231 formatted datetime string","type":"string"},"Last-Modified":{"description":"RFC7231 formatted datetime string","type":"string"}},"schema":{"description":"200 ok object","properties":{"attackers":{"description":"attackers array","items":{"description":"attacker object","properties":{"alliance_id":{"description":"alliance_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_alliance_id","type":"integer"},"character_id":{"description":"character_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_character_id","type":"integer"},"corporation_id":{"description":"corporation_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_corporation_id","type":"integer"},"damage_done":{"description":"damage_done integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_damage_done","type":"integer"},"faction_id":{"description":"faction_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_faction_id","type":"integer"},"final_blow":{"description":"Was the attacker the one to achieve the final blow\n","title":"get_killmails_killmail_id_killmail_hash_final_blow","type":"boolean"},"security_status":{"description":"Security status for the attacker\n","format":"float","title":"get_killmails_killmail_id_killmail_hash_security_status","type":"number"},"ship_type_id":{"description":"What ship was the attacker flying\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_ship_type_id","type":"integer"},"weapon_type_id":{"description":"What weapon was used by the attacker for the kill\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_weapon_type_id","type":"integer"}},"required":["security_status","final_blow","damage_done"],"title":"get_killmails_killmail_id_killmail_hash_attacker","type":"object"},"maxItems":10000,"title":"get_killmails_killmail_id_killmail_hash_attackers","type":"array"},"killmail_id":{"description":"ID of the killmail","format":"int32","title":"get_killmails_killmail_id_killmail_hash_killmail_id","type":"integer"},"killmail_time":{"description":"Time that the victim was killed and the killmail generated\n","format":"date-time","title":"get_killmails_killmail_id_killmail_hash_killmail_time","type":"string"},"moon_id":{"description":"Moon if the kill took place at one","format":"int32","title":"get_killmails_killmail_id_killmail_hash_moon_id","type":"integer"},"solar_system_id":{"description":"Solar system that the kill took place in\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_solar_system_id","type":"integer"},"victim":{"description":"victim object","properties":{"alliance_id":{"description":"alliance_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_victim_alliance_id","type":"integer"},"character_id":{"description":"character_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_victim_character_id","type":"integer"},"corporation_id":{"description":"corporation_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_victim_corporation_id","type":"integer"},"damage_taken":{"description":"How much total damage was taken by the victim\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_damage_taken","type":"integer"},"faction_id":{"description":"faction_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_victim_faction_id","type":"integer"},"items":{"description":"items array","items":{"description":"item object","properties":{"flag":{"description":"Flag for the location of the item\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_flag","type":"integer"},"item_type_id":{"description":"item_type_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_item_type_id","type":"integer"},"items":{"description":"items array","items":{"description":"item object","properties":{"flag":{"description":"flag integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_item_flag","type":"integer"},"item_type_id":{"description":"item_type_id integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_item_item_type_id","type":"integer"},"quantity_destroyed":{"description":"quantity_destroyed integer","format":"int64","title":"get_killmails_killmail_id_killmail_hash_item_quantity_destroyed","type":"integer"},"quantity_dropped":{"description":"quantity_dropped integer","format":"int64","title":"get_killmails_killmail_id_killmail_hash_item_quantity_dropped","type":"integer"},"singleton":{"description":"singleton integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_item_singleton","type":"integer"}},"required":["item_type_id","singleton","flag"],"title":"get_killmails_killmail_id_killmail_hash_items_item","type":"object"},"maxItems":10000,"title":"get_killmails_killmail_id_killmail_hash_item_items","type":"array"},"quantity_destroyed":{"description":"How many of the item were destroyed if any\n","format":"int64","title":"get_killmails_killmail_id_killmail_hash_quantity_destroyed","type":"integer"},"quantity_dropped":{"description":"How many of the item were dropped if any\n","format":"int64","title":"get_killmails_killmail_id_killmail_hash_quantity_dropped","type":"integer"},"singleton":{"description":"singleton integer","format":"int32","title":"get_killmails_killmail_id_killmail_hash_singleton","type":"integer"}},"required":["item_type_id","singleton","flag"],"title":"get_killmails_killmail_id_killmail_hash_item","type":"object"},"maxItems":10000,"title":"get_killmails_killmail_id_killmail_hash_items","type":"array"},"position":{"description":"Coordinates of the victim in Cartesian space relative to the Sun\n","properties":{"x":{"description":"x number","format":"double","title":"get_killmails_killmail_id_killmail_hash_x","type":"number"},"y":{"description":"y number","format":"double","title":"get_killmails_killmail_id_killmail_hash_y","type":"number"},"z":{"description":"z number","format":"double","title":"get_killmails_killmail_id_killmail_hash_z","type":"number"}},"required":["x","y","z"],"title":"get_killmails_killmail_id_killmail_hash_position","type":"object"},"ship_type_id":{"description":"The ship that the victim was piloting and was destroyed\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_victim_ship_type_id","type":"integer"}},"required":["damage_taken","ship_type_id"],"title":"get_killmails_killmail_id_killmail_hash_victim","type":"object"},"war_id":{"description":"War if the killmail is generated in relation to an official war\n","format":"int32","title":"get_killmails_killmail_id_killmail_hash_war_id","type":"integer"}},"required":["killmail_id","killmail_time","victim","attackers","solar_system_id"],"title":"get_killmails_killmail_id_killmail_hash_ok","type":"object"}},"304":{"description":"Not modified","headers":{"Cache-Control":{"description":"The caching mechanism used","type":"string"},"ETag":{"description":"RFC7232 compliant entity tag","type":"string"},"Expires":{"description":"RFC7231 formatted datetime string","type":"string"},"Last-Modified":{"description":"RFC7231 formatted datetime string","type":"string"}}},"400":{"description":"Bad request","examples":{"application/json":{"error":"Bad request message"}},"schema":{"$ref":"#/definitions/bad_request"}},"420":{"description":"Error limited","examples":{"application/json":{"error":"Error limited message"}},"schema":{"$ref":"#/definitions/error_limited"}},"422":{"description":"Invalid killmail_id and/or killmail_hash","examples":{"application/json":{"error":"Unprocessable entity message"}},"schema":{"description":"Unprocessable entity","properties":{"error":{"description":"Unprocessable entity message","title":"get_killmails_killmail_id_killmail_hash_422_unprocessable_entity","type":"string"}},"title":"get_killmails_killmail_id_killmail_hash_unprocessable_entity","type":"object"}},"500":{"description":"Internal server error","examples":{"application/json":{"error":"Internal server error message"}},"schema":{"$ref":"#/definitions/internal_server_error"}},"503":{"description":"Service unavailable","examples":{"application/json":{"error":"Service unavailable message"}},"schema":{"$ref":"#/definitions/service_unavailable"}},"504":{"description":"Gateway timeout","examples":{"application/json":{"error":"Gateway timeout message"}},"schema":{"$ref":"#/definitions/gateway_timeout"}}},"summary":"Get a single killmail","tags":["Killmails"],"x-alternate-versions":["dev","legacy","v1"],"x-cached-seconds":1209600}}},"produces":["application/json"],"schemes":["https"],"securityDefinitions":{"evesso":{"authorizationUrl":"https://login.eveonline.com/v2/oauth/authorize","flow":"implicit","scopes":{},"type":"oauth2"}},"swagger":"2.0"} \ No newline at end of file