From 07442a7b98f9f5379c19e1f822b8c800e60354f4 Mon Sep 17 00:00:00 2001 From: Midgard Date: Sun, 6 Dec 2020 02:08:50 +0100 Subject: [PATCH] Fix table maker --- make_table.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/make_table.py b/make_table.py index 2f855d1..bc490b0 100755 --- a/make_table.py +++ b/make_table.py @@ -9,7 +9,7 @@ from functools import partial if sys.stdin.isatty(): print("Hint: stdin is a terminal, you may want to do `./make_table.py < verifications.log` instead.", file=sys.stderr) -users = defaultdict(partial(defaultdict, dict)) +users = {} for line_nr, line in enumerate(sys.stdin, start=1): line = line.rstrip() @@ -22,6 +22,10 @@ for line_nr, line in enumerate(sys.stdin, start=1): verifier = m.group(4) verification_time = datetime.fromisoformat(m.group(5)) + if awardee not in users: + users[awardee] = {} + if post_id not in users[awardee]: + users[awardee][post_id] = defaultdict(dict) users[awardee][post_id][verifier] = verification_time continue @@ -33,10 +37,17 @@ for line_nr, line in enumerate(sys.stdin, start=1): try: del users[awardee][post_id][verifier] + # If no more verifiers left, the dict, this makes it easier to count + if not users[awardee][post_id]: + del users[awardee][post_id] + if not users[awardee]: + del users[awardee] except KeyError: print(f"Trying to remove non-existing verification by {verifier}, looks like the file is corrupt!", file=sys.stderr) continue + print(f"Couldn't parse line, looks like the file is corrupt: {line}", file=sys.stderr) + for username, user_posts in users.items(): print(f"{username}: {len(user_posts)}")