From f0c5c468c75a780bed55fabd91e8b153e27bf804 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 25 May 2022 00:20:53 +0200 Subject: Streamlined quote and blanks formatting --- scrap.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scrap.py b/scrap.py index 84c2b2d..29c77ab 100644 --- a/scrap.py +++ b/scrap.py @@ -21,7 +21,7 @@ def get_hash(kill): data = response.json() if len(data) > 1: raise ValueError() - return data[0]["zkb"]["hash"] + return data[0]['zkb']['hash'] class RelatedParser(HTMLParser): @@ -36,15 +36,12 @@ class RelatedParser(HTMLParser): def handle_starttag(self, tag, attrs): attrs = dict(attrs) - if tag == "table" and attrs.get("id", "").lower() == "killlist": self._team += 1 - if tag == "tr" and attrs.get("class", "").lower() == "killlistrow" and self._team > 0: self._flush() killid = attrs.get("killid", "") self._current = (killid, self._team, None) - if tag == "a" and self._team > 0 and self._current: match = OWNER_HREF.match(attrs.get("href", "")) if match: @@ -77,19 +74,19 @@ def get_related_kills(url): killmails = [] teams = (set(), set()) for kill, team, victim in related.kills: - killmails.append({"id": int(kill)}) + killmails.append({'id': int(kill)}) destination = teams[team - 1] destination.add(int(victim)) - return {"killmails": killmails, "teams": list(map(list, teams))} + 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"]: + for killmail in snapshot['killmails']: time.sleep(1.05) # Zkillboard is very sensitive. - killmail["hash"] = get_hash(killmail["id"]) + killmail['hash'] = get_hash(killmail['id']) return snapshot @@ -139,7 +136,7 @@ def main(): expand_hashes(snapshot) expand_details(snapshot) filename = output_name(args) - with open(filename, "w") as fd: + with open(filename, 'w') as fd: opts = {'indent': 4} if args.pretty else {} fd.write(json.dumps(snapshot, **opts)) fd.write("\n") -- cgit v1.1