Fix table maker

This commit is contained in:
Midgard 2020-12-06 02:08:50 +01:00
parent f35779de6d
commit 07442a7b98
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -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)}")