From 4f24dc1fb9c42370726f0b5daec35d38b2459513 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 24 May 2022 23:54:40 +0200 Subject: Separated out a function that finds hashes for all killmails in snapshot --- scrap.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scrap.py b/scrap.py index 769271a..b396ccb 100644 --- a/scrap.py +++ b/scrap.py @@ -66,6 +66,9 @@ class RelatedParser(HTMLParser): def get_related_kills(url): + """ + Builds basic snapshot containing all killmails from battle report at *url*. + """ response = requests.get(url) response.raise_for_status() page = response.text @@ -74,13 +77,22 @@ def get_related_kills(url): killmails = [] teams = (set(), set()) for kill, team, victim in related.kills: - time.sleep(1.05) # Zkillboard is very sensitive. - killmails.append({"id": int(kill), "hash": get_hash(kill)}) + killmails.append({"id": int(kill)}) destination = teams[team - 1] destination.add(int(victim)) return {"killmails": killmails, "teams": list(map(list, teams))} +def expand_hashes(snapshot): + """ + Expands killmails in *snapshot* IN PLACE by adding their hash based on information from Zkillboard. + """ + for killmail in snapshot["killmails"]: + killmail["hash"] = get_hash(killmail["id"]) + time.sleep(1.05) # Zkillboard is very sensitive. + return snapshot + + def output_name(args): """ Generates name of the output file based on the CLI *args*. @@ -99,6 +111,7 @@ def main(): parser.add_argument("-o", "--output") args = parser.parse_args() snapshot = get_related_kills(args.url) + expand_hashes(snapshot) filename = output_name(args) with open(filename, "w") as fd: fd.write(json.dumps(snapshot)) -- cgit v1.1