Move out of try block, fix typo, add line number

This commit is contained in:
Midgard 2020-12-06 02:29:45 +01:00
parent 16ee5fd08d
commit d88afa7a58
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -37,17 +37,18 @@ 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
except KeyError:
print(f"Line {line_nr}: trying to remove non-existing verification by {verifier}, looks like the file is corrupt!", file=sys.stderr)
# If no more verifiers left, clean up the dicts, 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)
print(f"Couldn't parse line {line_nr}, looks like the file is corrupt: {line}", file=sys.stderr)
for username, user_posts in users.items():
print(f"{username}: {len(user_posts)}")