Created
May 31, 2015 05:26
-
-
Save int64ago/414f4f4ae59946d5418f to your computer and use it in GitHub Desktop.
Extract Money & Jetton info from replay.txt
This file contains 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
#!/usr/bin/python | |
import sys, re, StringIO, json | |
data = {'data': []} | |
def findPlayer(_id): | |
for player in data['data']: | |
if player['name'] == _id: | |
return player | |
cont = '' | |
try: | |
f = open(sys.argv[1], 'r') | |
cont = f.read() | |
f.close() | |
except: | |
print('Usage: python extract.py replay.txt') | |
patt = r'seat/([\s\S]+?)/seat' | |
results = re.findall(patt, cont) | |
for idx, res in enumerate(results): | |
buf = StringIO.StringIO(res) | |
for line in buf.readlines(): | |
line = line.strip() | |
if line: | |
player = line.split(':')[-1].strip().split(' ') | |
if findPlayer(player[0]): | |
findPlayer(player[0])['data'].append(int(player[1]) + int(player[2])) | |
else: | |
newPlayer = { | |
'name': player[0], | |
'data': [int(player[1]) + int(player[2])] | |
} | |
data['data'].append(newPlayer) | |
f = open('replay.json', 'w') | |
f.write(json.dumps(data)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment