Created
September 23, 2023 18:01
-
-
Save orangepeelbeef/9843a36080b949c230e293d456dc4547 to your computer and use it in GitHub Desktop.
FoundryVTT PF2e Chat log parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env/python | |
import os | |
import re | |
from collections import Counter | |
def parse_event(data, roll_log, roll_count): | |
my_data = data.split("\n") | |
match = re.match('\[.+\]\s(.+)$', my_data[0]) | |
if match: | |
user = match.group(1) | |
if user not in roll_log: | |
roll_log[user] = [] | |
if user not in roll_count: | |
roll_count[user] = 0 | |
else: | |
print(f'Error cannot parse event {data}') | |
exit(1) | |
match = re.match('^\d+$', my_data[1]) | |
if match: | |
# this is a roll result | |
# we don't care about the final result we want the actual die roll | |
# but we only want to parse events that have a roll | |
match = re.match('1d20\s\+\s\d+\s=\s(\d+)', my_data[2]) | |
if match: | |
roll_log[user].append(match.group(1)) | |
roll_count[user] += 1 | |
def player_report(the_players, the_log, the_count): | |
for player in the_players: | |
r = Counter(the_log[player]) | |
print(f'Player: {player} Total Rolls: {the_count[player]} Statistics: {r}') | |
roll_log = {} | |
roll_count = {} | |
players = ['Ed Gruberman', 'Valeria Brightshield', 'Ziggie', 'Camila Ramos'] | |
downloads = os.path.expanduser("~/Downloads") | |
with open(f"{downloads}/fvtt-log-Sat-Sep-23-2023.txt", encoding='utf-8') as f: | |
event = "" | |
while line := f.readline(): | |
if line.rstrip() == '---------------------------': | |
# end of event | |
parse_event(event, roll_log, roll_count) | |
event = "" | |
else: | |
event += line | |
player_report(players, roll_log, roll_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment