From 60108df287818a565e40263f159db5375e9e831d Mon Sep 17 00:00:00 2001 From: Mr McClain Date: Tue, 22 Mar 2016 20:10:36 -0500 Subject: [PATCH] inital commit --- services/managers/srp_manager.py | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 services/managers/srp_manager.py diff --git a/services/managers/srp_manager.py b/services/managers/srp_manager.py new file mode 100644 index 00000000..d7c30ff4 --- /dev/null +++ b/services/managers/srp_manager.py @@ -0,0 +1,46 @@ +from django.conf import settings + + +import json +import urllib2 +import logging + + +logger = logging.getLogger(__name__) + +class srpManager(): + @staticmethod + def get_kill_id (killboard_link): + str = (killboard_link) + set = '0123456789' + kill_id = ''.join([c for c in str if c in set]) + + @staticmethod + def get_kill_data (kill_id): + url = ("https://www.zkillboard.com/api/killID/%s" % kill_id) + request = urllib2.Request(url) + request.add_header('User-Agent',"%s Alliance Auth" % settings.DOMAIN) + request.add_header('Content-Type','application/json') + response = urllib2.urlopen(request) + result = json.load(response)[0] + if result: + ship_type = result['victim']['shipTypeID'] + logger.debug("Ship type for kill ID %s is determined to be %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)) + else: + raise ValueError("Invalid Kill ID") + + @staticmethod + def get_ship_name (ship_type): + url = ("https://jetbalsa.com/api/json.php/invTypes/%s" % ship_type) + request = urllib2.Request(url) + request.add_header('User-Agent',"%s Alliance Auth" % settings.DOMAIN) + request.add_header('Content-Type','application/json') + response = urllib2.urlopen(request) + result = json.load(response) + if result: + ship_name = result['typeName'] + logger.debug("ship type %s determined to be %s" % (ship_type, ship_name)) + else: + logger.info("ship type %s is invalid please try again" % ship_type)