diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 80637445..05f9d6df 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -47,17 +47,20 @@ class Everleaf(HandHistoryConverter): except: self.ofile = os.path.join(self.hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file)) - def compilePlayerRegexs(self): - player_re = "(?P" + "|".join(map(re.escape, self.players)) + ")" - #print "DEBUG player_re: " + player_re - self.re_PostSB = re.compile(r"^%s: posts small blind \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_PostBB = re.compile(r"^%s: posts big blind \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_PostBoth = re.compile(r"^%s: posts both blinds \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_HeroCards = re.compile(r"^Dealt to %s \[ (?P.*) \]" % player_re, re.MULTILINE) - self.re_Action = re.compile(r"^%s(?P: bets| checks| raises| calls| folds)(\s\[\$ (?P[.\d]+) (USD|EUR)\])?" % player_re, re.MULTILINE) - self.re_ShowdownAction = re.compile(r"^%s shows \[ (?P.*) \]" % player_re, re.MULTILINE) - self.re_CollectPot = re.compile(r"^%s wins \$ (?P[.\d]+) (USD|EUR)(.*?\[ (?P.*?) \])?" % player_re, re.MULTILINE) - self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) + def compilePlayerRegexs(self, players): + if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' + # we need to recompile the player regexs. + self.compiledPlayers = players + player_re = "(?P" + "|".join(map(re.escape, players)) + ")" + logging.debug("player_re: "+ player_re) + self.re_PostSB = re.compile(r"^%s: posts small blind \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_PostBB = re.compile(r"^%s: posts big blind \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_PostBoth = re.compile(r"^%s: posts both blinds \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_HeroCards = re.compile(r"^Dealt to %s \[ (?P.*) \]" % player_re, re.MULTILINE) + self.re_Action = re.compile(r"^%s(?P: bets| checks| raises| calls| folds)(\s\[\$ (?P[.\d]+) (USD|EUR)\])?" % player_re, re.MULTILINE) + self.re_ShowdownAction = re.compile(r"^%s shows \[ (?P.*) \]" % player_re, re.MULTILINE) + self.re_CollectPot = re.compile(r"^%s wins \$ (?P[.\d]+) (USD|EUR)(.*?\[ (?P.*?) \])?" % player_re, re.MULTILINE) + self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) def readSupportedGames(self): return [["ring", "hold", "nl"], diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index 0a47f026..038b63ad 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -39,20 +39,23 @@ class FullTilt(HandHistoryConverter): self.sitename = "FullTilt" self.setFileType("text", "cp1252") - def compilePlayerRegexs(self): - player_re = "(?P" + "|".join(map(re.escape, self.players)) + ")" - print "DEBUG player_re: " + player_re - self.re_PostSB = re.compile(r"^%s posts the small blind of \$?(?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_PostBB = re.compile(r"^%s posts (the big blind of )?\$?(?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_Antes = re.compile(r"^%s antes \$?(?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_BringIn = re.compile(r"^%s brings in for \$?(?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_PostBoth = re.compile(r"^%s posts small \& big blinds \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_HeroCards = re.compile(r"^Dealt to %s \[(?P[AKQJT0-9hcsd ]+)\]( \[(?P[AKQJT0-9hcsd ]+)\])?" % player_re, re.MULTILINE) - self.re_Action = re.compile(r"^%s(?P bets| checks| raises to| calls| folds)(\s\$(?P[.\d]+))?" % player_re, re.MULTILINE) - self.re_ShowdownAction = re.compile(r"^%s shows \[(?P.*)\]" % player_re, re.MULTILINE) - self.re_CollectPot = re.compile(r"^Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P[.\d]+)\)(, mucked| with.*)" % player_re, re.MULTILINE) - self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) - self.re_ShownCards = re.compile(r"^Seat (?P[0-9]+): %s \(.*\) showed \[(?P.*)\].*" % player_re, re.MULTILINE) + def compilePlayerRegexs(self, players): + if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' + # we need to recompile the player regexs. + self.compiledPlayers = players + player_re = "(?P" + "|".join(map(re.escape, players)) + ")" + logging.debug("player_re: " + player_re) + self.re_PostSB = re.compile(r"^%s posts the small blind of \$?(?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_PostBB = re.compile(r"^%s posts (the big blind of )?\$?(?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_Antes = re.compile(r"^%s antes \$?(?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_BringIn = re.compile(r"^%s brings in for \$?(?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_PostBoth = re.compile(r"^%s posts small \& big blinds \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_HeroCards = re.compile(r"^Dealt to %s \[(?P[AKQJT0-9hcsd ]+)\]( \[(?P[AKQJT0-9hcsd ]+)\])?" % player_re, re.MULTILINE) + self.re_Action = re.compile(r"^%s(?P bets| checks| raises to| calls| folds)(\s\$(?P[.\d]+))?" % player_re, re.MULTILINE) + self.re_ShowdownAction = re.compile(r"^%s shows \[(?P.*)\]" % player_re, re.MULTILINE) + self.re_CollectPot = re.compile(r"^Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P[.\d]+)\)(, mucked| with.*)" % player_re, re.MULTILINE) + self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) + self.re_ShownCards = re.compile(r"^Seat (?P[0-9]+): %s \(.*\) showed \[(?P.*)\].*" % player_re, re.MULTILINE) def readSupportedGames(self): diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 7558db48..59d0365a 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -92,6 +92,7 @@ class HandHistoryConverter: self.ofile = os.path.join(self.hhdir, os.path.basename(file)) self.rexx = FpdbRegex.FpdbRegex() self.players = set() + self.compiledPlayers = set() self.maxseats = 10 def __str__(self): @@ -118,7 +119,7 @@ class HandHistoryConverter: return self.obs = self.obs.replace('\r\n', '\n') - self.gametype = self.determineGameType() + self.gametype = self.determineGameType(self.obs) if self.gametype == None: print "Unknown game type from file, aborting on this file." return @@ -138,7 +139,7 @@ class HandHistoryConverter: else: # we need to recompile the player regexs. self.players = playersThisHand - self.compilePlayerRegexs() + self.compilePlayerRegexs(playersThisHand) self.markStreets(hand) # Different calls if stud or holdem like