Skip to content

Instantly share code, notes, and snippets.

@paxswill
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paxswill/14301998e1cb6e3be4b6 to your computer and use it in GitHub Desktop.
Save paxswill/14301998e1cb6e3be4b6 to your computer and use it in GitHub Desktop.
from evesrp.killmail import CRESTMail
class SubmittedCRESTZKillmail(CRESTMail):
"""Accepts and validates CREST killmail links, but submits them to
ZKillboard and substitutes the zKB link in as the canonical link
"""
def __init__(self, url, **kwargs):
# Let CRESTMail validate the CREST link
super(self.__class__, self).__init__(url, **kwargs)
# Submit the CREST URL to ZKillboard
resp = self.requests_session.post('https://zkillboard.com/post/',
data={'killmailurl': url})
# Use the URL we get from ZKillboard as the new URL
self.url = resp.url
# Grab zkb's data from their API
api_url = ('https://zkillboard.com/api/no-attackers/'
'no-items/killID/{}').format(self.kill_id)
zkb_api = self.requests_session.get(api_url)
retrieval_error = LookupError(u"Error retrieving killmail data (zKB): {}"
.format(zkb_api.status_code))
if zkb_api.status_code != 200:
raise retrieval_error
try:
json = zkb_api.json()
except ValueError as e:
raise retrieval_error
try:
json = json[0]
except IndexError as e:
raise LookupError(u"Invalid killmail: {}".format(url))
# The only thing CREST doesn't give us is the value, which new versions
# of zkb return
# Python2 hates passing these classes around, so we're stuck importing the
from decimal import Decimal
try:
self.value = Decimal(json[u'zkb'][u'totalValue'])
except KeyError:
self.value = Decimal(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment