diff options
author | Aki <please@ignore.pl> | 2022-05-24 23:54:40 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-05-24 23:54:40 +0200 |
commit | 4f24dc1fb9c42370726f0b5daec35d38b2459513 (patch) | |
tree | 51d30f47b23073fcab777db37e851f0367fbe7ef | |
parent | 03e7e8de1ff72be84e0759666bd5677606fc3ef7 (diff) | |
download | salvager-4f24dc1fb9c42370726f0b5daec35d38b2459513.zip salvager-4f24dc1fb9c42370726f0b5daec35d38b2459513.tar.gz salvager-4f24dc1fb9c42370726f0b5daec35d38b2459513.tar.bz2 |
Separated out a function that finds hashes for all killmails in snapshot
-rw-r--r-- | scrap.py | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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)) |