2020-12-06 01:53:40 +01:00
|
|
|
#!/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)
|
|
|
|
|
2020-12-06 02:08:50 +01:00
|
|
|
users = {}
|
2020-12-06 01:53:40 +01:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
2020-12-06 02:08:50 +01:00
|
|
|
if awardee not in users:
|
|
|
|
users[awardee] = {}
|
|
|
|
if post_id not in users[awardee]:
|
|
|
|
users[awardee][post_id] = defaultdict(dict)
|
2020-12-06 01:53:40 +01:00
|
|
|
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:
|
2020-12-06 02:29:45 +01:00
|
|
|
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]
|
2020-12-06 01:53:40 +01:00
|
|
|
|
|
|
|
continue
|
|
|
|
|
2020-12-06 02:29:45 +01:00
|
|
|
print(f"Couldn't parse line {line_nr}, looks like the file is corrupt: {line}", file=sys.stderr)
|
2020-12-06 02:08:50 +01:00
|
|
|
|
2020-12-06 01:53:40 +01:00
|
|
|
for username, user_posts in users.items():
|
|
|
|
print(f"{username}: {len(user_posts)}")
|