From 0c64bf2badeab249c9da087c8a0042b816f9427e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 25 May 2022 20:11:18 +0200 Subject: Added names to the snapshot --- salvager/esi.py | 17 +++++++++++++---- scrap.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/salvager/esi.py b/salvager/esi.py index d6acf30..5ded1d4 100644 --- a/salvager/esi.py +++ b/salvager/esi.py @@ -1,7 +1,7 @@ import requests -def _make_endpoint(path, include=None, exclude=None, trim=None): +def _make_endpoint(path, include=None, exclude=None, trim=None, method=requests.get): def _trim(data): if include: data = {k: v for k, v in data.items() if k in include} @@ -14,13 +14,13 @@ def _make_endpoint(path, include=None, exclude=None, trim=None): if not callable(trim): trim = _trim - def _get(*args): + def _method(*args, **kwargs): query = "https://esi.evetech.net/latest/" + path + "?datasource=tranquility" - response = requests.get(query.format(*args)) + response = method(query.format(*args), **kwargs) response.raise_for_status() return trim(response.json()) - return _get + return _method def _trim_killmail(km): @@ -30,9 +30,18 @@ def _trim_killmail(km): return km +def _trim_names(names): + for name in names: + del name['category'] + return names + + killmail = _make_endpoint("killmails/{}/{}/", trim=_trim_killmail) type = _make_endpoint("universe/types/{}/", include=['type_id', 'name', 'group_id']) system = _make_endpoint( "universe/systems/{}/", include=['system_id', 'constellation_id', 'name', 'position', 'security_status']) constellation = _make_endpoint("universe/constellations/{}/", include=['region_id', 'name']) region = _make_endpoint("universe/regions/{}/", include=['name']) +names = _make_endpoint("universe/names/", method=requests.post, trim=_trim_names) +corporation = _make_endpoint("corporations/{}/", include=['corporation_id', 'name', 'ticker']) +alliance = _make_endpoint("alliances/{}/", include=['alliance_id', 'name', 'ticker']) diff --git a/scrap.py b/scrap.py index 0a5c7d9..c430f36 100644 --- a/scrap.py +++ b/scrap.py @@ -53,6 +53,25 @@ def get_locations(snapshot): return solar_systems +def get_names(snapshot): + fields = ['alliance_id', 'character_id', 'corporation_id', 'faction_id'] + misc = set() + alliances = set() + corporations = set() + for km in snapshot['killmails']: + victim = km['victim'] + for field in fields: + if field in victim and victim[field] > 0: + misc.add(victim[field]) + if 'alliance_id' in victim: + alliances.add(victim['alliance_id']) + corporations.add(victim['corporation_id']) + names = esi.names(json=list(misc)) + names += [{'id': x, **esi.corporation(x)} for x in corporations] + names += [{'id': x, **esi.alliance(x)} for x in alliances] + return names + + def output_name(args): """ Generates name of the output file based on the CLI *args*. @@ -76,6 +95,7 @@ def main(): expand_details(snapshot) snapshot['types'] = get_types(snapshot) snapshot['locations'] = get_locations(snapshot) + snapshot['names'] = get_names(snapshot) filename = output_name(args) with open(filename, 'w') as fd: opts = {'indent': 4} if args.pretty else {} -- cgit v1.1