2 # -*- coding: utf-8 -*-
4 #Copyright 2009-2011 Carl Gherardi
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
19 _
= L10n
.get_translation()
25 import HandHistoryConverter
30 # ./Anonymise.py -f <valid path to HH file> -k <name of input filter>
32 (options
, argv
) = Options
.fpdb_options()
34 config
= Configuration
.Config(options
.config
)
36 config
= Configuration
.Config()
40 filter_name
= filter.replace("ToFpdb", "")
42 mod
= __import__(filter)
43 obj
= getattr(mod
, filter_name
, None)
45 hhc
= obj(config
, autostart
=False)
47 for kodec
in ("utf8", "cp1252", "utf-16"):
48 if os
.path
.exists(options
.filename
):
49 in_fh
= codecs
.open(options
.filename
, 'r', kodec
)
50 filecontents
= in_fh
.read()
54 print(_("Could not find file %s") % options
.filename
)
57 m
= hhc
.re_PlayerInfo
.finditer(filecontents
)
59 outfile
= options
.filename
+".anon"
60 print(_("Output being written to %s") % outfile
)
62 savestdout
= sys
.stdout
63 fsock
= open(outfile
,"w")
68 players
= players
+ [a
.group('PNAME')]
72 for i
, name
in enumerate(uniq
):
73 filecontents
= filecontents
.replace(name
, 'Player%d' %i)
77 sys
.stdout
= savestdout