Fix table maker
This commit is contained in:
parent
f35779de6d
commit
07442a7b98
1 changed files with 12 additions and 1 deletions
|
@ -9,7 +9,7 @@ from functools import partial
|
||||||
if sys.stdin.isatty():
|
if sys.stdin.isatty():
|
||||||
print("Hint: stdin is a terminal, you may want to do `./make_table.py < verifications.log` instead.", file=sys.stderr)
|
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):
|
for line_nr, line in enumerate(sys.stdin, start=1):
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
|
@ -22,6 +22,10 @@ for line_nr, line in enumerate(sys.stdin, start=1):
|
||||||
verifier = m.group(4)
|
verifier = m.group(4)
|
||||||
verification_time = datetime.fromisoformat(m.group(5))
|
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
|
users[awardee][post_id][verifier] = verification_time
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -33,10 +37,17 @@ for line_nr, line in enumerate(sys.stdin, start=1):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
del users[awardee][post_id][verifier]
|
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:
|
except KeyError:
|
||||||
print(f"Trying to remove non-existing verification by {verifier}, looks like the file is corrupt!", file=sys.stderr)
|
print(f"Trying to remove non-existing verification by {verifier}, looks like the file is corrupt!", file=sys.stderr)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
print(f"Couldn't parse line, looks like the file is corrupt: {line}", file=sys.stderr)
|
||||||
|
|
||||||
for username, user_posts in users.items():
|
for username, user_posts in users.items():
|
||||||
print(f"{username}: {len(user_posts)}")
|
print(f"{username}: {len(user_posts)}")
|
||||||
|
|
Loading…
Reference in a new issue