From 286d663f05c03b56b6510080db806794b4891150 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 25 May 2022 18:48:11 +0200 Subject: Added type details and moved esi stuff to own module --- scrap.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'scrap.py') diff --git a/scrap.py b/scrap.py index dc10eb5..2939451 100644 --- a/scrap.py +++ b/scrap.py @@ -7,6 +7,8 @@ from html.parser import HTMLParser import requests +from salvager import esi + OWNER_HREF = re.compile(r"/(?:corporation|alliance)/(\d+)/?") SYSTEM_AND_DATE = re.compile(r"/(\d+)/(\d+)/?$") @@ -90,30 +92,22 @@ def expand_hashes(snapshot): return snapshot -def get_details(kill, hash): - """ - Retrieves detailed information about killmail from EVE ESI using killmail's *kill* ID and *hash*. - """ - query = "https://esi.evetech.net/latest/killmails/{}/{}/?datasource=tranquility" - response = requests.get(query.format(kill, hash)) - response.raise_for_status() - return response.json() - - def expand_details(snapshot): """ Expands killmails in *snapshot* IN PLACE by adding details from EVE ESI. Some data is dropped in process as e.g., full information on attackers is not important in context of the visualizations. """ for killmail in snapshot['killmails']: - details = get_details(killmail['killmail_id'], killmail['hash']) - del details['attackers'] - del details['victim']['items'] - del details['victim']['damage_taken'] + details = esi.killmail(killmail['killmail_id'], killmail['hash']) killmail.update(details) return snapshot +def get_ships(snapshot): + ships = {x['victim']['ship_type_id'] for x in snapshot['killmails']} + return [esi.type(x) for x in ships] + + def output_name(args): """ Generates name of the output file based on the CLI *args*. @@ -135,6 +129,7 @@ def main(): snapshot = get_related_kills(args.url) expand_hashes(snapshot) expand_details(snapshot) + snapshot['ships'] = get_ships(snapshot) filename = output_name(args) with open(filename, 'w') as fd: opts = {'indent': 4} if args.pretty else {} -- cgit v1.1