2009-12-03 10:26:40 +01:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import codecs
|
|
|
|
import Options
|
|
|
|
import HandHistoryConverter
|
2010-06-05 12:00:41 +02:00
|
|
|
import Configuration
|
2010-06-06 22:06:04 +02:00
|
|
|
import sys
|
2009-12-03 10:26:40 +01:00
|
|
|
|
|
|
|
(options, argv) = Options.fpdb_options()
|
2010-06-05 11:58:00 +02:00
|
|
|
config = Configuration.Config()
|
2009-12-03 10:26:40 +01:00
|
|
|
|
|
|
|
filter = options.hhc
|
|
|
|
|
|
|
|
filter_name = filter.replace("ToFpdb", "")
|
|
|
|
|
|
|
|
mod = __import__(filter)
|
|
|
|
obj = getattr(mod, filter_name, None)
|
|
|
|
|
2010-06-05 11:58:00 +02:00
|
|
|
hhc = obj(config, autostart=False)
|
2009-12-03 10:26:40 +01:00
|
|
|
|
|
|
|
if os.path.exists(options.infile):
|
|
|
|
in_fh = codecs.open(options.infile, 'r', "utf8")
|
|
|
|
filecontents = in_fh.read()
|
|
|
|
in_fh.close()
|
|
|
|
else:
|
|
|
|
print "Could not find file %s" % options.infile
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
m = hhc.re_PlayerInfo.finditer(filecontents)
|
|
|
|
|
2010-06-06 22:06:04 +02:00
|
|
|
outfile = options.infile+".anon"
|
|
|
|
print "Output being written to", outfile
|
|
|
|
|
|
|
|
savestdout = sys.stdout
|
|
|
|
fsock = open(outfile,"w")
|
|
|
|
sys.stdout = fsock
|
|
|
|
|
2009-12-03 10:26:40 +01:00
|
|
|
players = []
|
|
|
|
for a in m:
|
|
|
|
players = players + [a.group('PNAME')]
|
|
|
|
|
|
|
|
uniq = set(players)
|
|
|
|
|
2010-06-05 11:58:00 +02:00
|
|
|
for i, name in enumerate(uniq):
|
2009-12-03 10:26:40 +01:00
|
|
|
filecontents = filecontents.replace(name, 'Player%d' %i)
|
|
|
|
|
|
|
|
print filecontents
|
2010-06-06 22:06:04 +02:00
|
|
|
|
|
|
|
sys.stdout = savestdout
|
|
|
|
fsock.close()
|
|
|
|
|