From 1820e7105476ae1f7491ec98df1b4b2560de6696 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 30 Jul 2009 18:06:13 -0400 Subject: [PATCH 1/3] Started on supporting expected HH change--rewrote GameType regex. This version should work with the expected HH format for $ tables only. I abstracted the ISO currency codes and currency symbols out of the regex so they only need to be maintained in 1 place. I didn't apply the change to everywhere "\$" appears, in case comments are negative. --- pyfpdb/PokerStarsToFpdb.py | 105 +++++++++---------------------------- 1 file changed, 25 insertions(+), 80 deletions(-) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 61d4df4c..f30b3df4 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -29,18 +29,31 @@ class PokerStars(HandHistoryConverter): ############################################################ # Class Variables + substitutions = { + 'LEGAL_ISO' : "USD|EUR|GBP|CAD", # legal ISO currency codes + 'LS' : "\$" # legal currency symbols + } + # Static regexes - re_GameInfo = re.compile("""PokerStars\sGame\s\#(?P[0-9]+):\s+ - (Tournament\s\#(?P\d+),\s(?P[\$\+\d\.]+)\s)? - (?PHORSE|8\-Game|HOSE)?\s?\(? - (?PHold\'em|Razz|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball)\s - (?PNo\sLimit|Limit|Pot\sLimit)\)?,?\s - (-\sLevel\s(?P[IVXLC]+)\s)?\(? - (?P\$|)? - (?P[.0-9]+)/\$? - (?P[.0-9]+)\)\s-\s - (?P.*$)""", - re.MULTILINE|re.VERBOSE) + re_GameInfo = re.compile(""" + PokerStars\sGame\s\#(?P[0-9]+):\s+ + (Tournament\s\# # open paren of tournament info + (?P\d+),\s + (?P[%(LS)s\+\d\.]+ # here's how I plan to use LS + \s?(?P%(LEGAL_ISO)s)? + )\s)? # close paren of tournament info + (?PHORSE|8\-Game|HOSE)?\s?\(? + (?PHold\'em|Razz|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball)\s + (?PNo\sLimit|Limit|Pot\sLimit)\)?,?\s + (-\sLevel\s(?P[IVXLC]+)\s)? + \(? # open paren of the stakes + (?P%(LS)s|)? + (?P[.0-9]+)/%(LS)s? + (?P[.0-9]+) + \s?(?P%(LEGAL_ISO)s)? + \)\s-\s # close paren of the stakes + (?P.*$)""" % substitutions, + re.MULTILINE|re.VERBOSE) re_SplitHands = re.compile('\n\n+') re_TailSplitHands = re.compile('(\n\n\n+)') re_HandInfo = re.compile("""^Table\s\'(?P[-\ a-zA-Z\d]+)\'\s @@ -121,6 +134,7 @@ follow : whether to tail -f the input""" return None mg = m.groupdict() + print "mg =", mg # translations from captured groups to fpdb info strings limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl' } games = { # base, category @@ -270,19 +284,6 @@ follow : whether to tail -f the input""" for a in self.re_PostBoth.finditer(hand.handText): hand.addBlind(a.group('PNAME'), 'both', a.group('SBBB')) -# def readHeroCards(self, hand): -# m = self.re_HeroCards.search(hand.handText) -# if(m == None): -# #Not involved in hand -# hand.involved = False -# else: -# hand.hero = m.group('PNAME') -# # "2c, qh" -> set(["2c","qc"]) -# # Also works with Omaha hands. -# cards = m.group('NEWCARDS') -# cards = set(cards.split(' ')) -# hand.addHoleCards(cards, m.group('PNAME'), shown=False, mucked=False, dealt=True) - def readHeroCards(self, hand): # streets PREFLOP, PREDRAW, and THIRD are special cases beacause # we need to grab hero's cards @@ -318,62 +319,6 @@ follow : whether to tail -f the input""" else: hand.addHoleCards(street, player, open=newcards, closed=oldcards, shown=False, mucked=False, dealt=False) - -# def readDrawCards(self, hand, street): -# logging.debug("readDrawCards") -# m = self.re_HeroCards.finditer(hand.streets[street]) -# if m == None: -# hand.involved = False -# else: -# for player in m: -# hand.hero = player.group('PNAME') # Only really need to do this once -# newcards = player.group('NEWCARDS') -# oldcards = player.group('OLDCARDS') -# if newcards == None: -# newcards = set() -# else: -# newcards = set(newcards.split(' ')) -# if oldcards == None: -# oldcards = set() -# else: -# oldcards = set(oldcards.split(' ')) -# hand.addDrawHoleCards(newcards, oldcards, player.group('PNAME'), street) - - -# def readStudPlayerCards(self, hand, street): -# # See comments of reference implementation in FullTiltToFpdb.py -# logging.debug("readStudPlayerCards") -# m = self.re_HeroCards.finditer(hand.streets[street]) -# for player in m: -# #~ logging.debug(player.groupdict()) -# (pname, oldcards, newcards) = (player.group('PNAME'), player.group('OLDCARDS'), player.group('NEWCARDS')) -# if oldcards: -# oldcards = [c.strip() for c in oldcards.split(' ')] -# if newcards: -# newcards = [c.strip() for c in newcards.split(' ')] -# if street=='ANTES': -# return -# elif street=='THIRD': -# # we'll have observed hero holecards in CARDS and thirdstreet open cards in 'NEWCARDS' -# # hero: [xx][o] -# # others: [o] -# hand.addPlayerCards(player = player.group('PNAME'), street = street, closed = oldcards, open = newcards) -# elif street in ('FOURTH', 'FIFTH', 'SIXTH'): -# # 4th: -# # hero: [xxo] [o] -# # others: [o] [o] -# # 5th: -# # hero: [xxoo] [o] -# # others: [oo] [o] -# # 6th: -# # hero: [xxooo] [o] -# # others: [ooo] [o] -# hand.addPlayerCards(player = player.group('PNAME'), street = street, open = newcards) -# # we may additionally want to check the earlier streets tally with what we have but lets trust it for now. -# elif street=='SEVENTH' and newcards: -# # hero: [xxoooo] [x] -# # others: not reported. -# hand.addPlayerCards(player = player.group('PNAME'), street = street, closed = newcards) def readAction(self, hand, street): m = self.re_Action.finditer(hand.streets[street]) From 29366d3bb6731c73966c8391a799db2358211d5d Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 30 Jul 2009 23:42:57 -0400 Subject: [PATCH 2/3] Ugly fix to prevent importing from failing due to undef positions array. --- pyfpdb/fpdb_parse_logic.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index fd2d6796..673254d0 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -167,7 +167,12 @@ def mainParser(settings, siteID, category, hand, config, db = None): except: print "parse: error during commit: " + str(sys.exc_value) - +# HERE's an ugly kludge to keep from failing when positions is undef +# We'll fix this by getting rid of the legacy importer. REB + try: + if positions: pass + except: + positions = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # save data structures in a HandToWrite instance and then insert into database: htw = Database.HandToWrite() htw.set_all( config, settings, base, category, siteTourneyNo, buyin From 5660b7735599316182e1b1586fc83ead199831ed Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 30 Jul 2009 23:44:59 -0400 Subject: [PATCH 3/3] Delete uneeded intermediate prints. --- pyfpdb/PokerStarsToFpdb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index f30b3df4..20ba4319 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -134,7 +134,6 @@ follow : whether to tail -f the input""" return None mg = m.groupdict() - print "mg =", mg # translations from captured groups to fpdb info strings limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl' } games = { # base, category