54 lines
1.6 KiB
Python
Executable file
54 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import re
|
|
from datetime import datetime
|
|
from collections import defaultdict
|
|
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 = {}
|
|
|
|
for line_nr, line in enumerate(sys.stdin, start=1):
|
|
line = line.rstrip()
|
|
|
|
m = re.fullmatch(r"([^ ]+) ([^ ]+) at ([^ ]+) verified by ([^ ]+) at ([^ ]+)", line)
|
|
if m:
|
|
awardee = m.group(1)
|
|
post_id = m.group(2)
|
|
post_time = datetime.fromisoformat(m.group(3))
|
|
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
|
|
|
|
m = re.fullmatch(r"([^ ]+) ([^ ]+) verification removed by ([^ ]+)", line)
|
|
if m:
|
|
awardee = m.group(1)
|
|
post_id = m.group(2)
|
|
verifier = m.group(3)
|
|
|
|
try:
|
|
del users[awardee][post_id][verifier]
|
|
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]
|
|
|
|
continue
|
|
|
|
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)}")
|