From a79dbd8f1b388c3bb0d008da0ece65af289b09c9 Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 2 Dec 2010 17:40:24 +0800 Subject: [PATCH] Party: First pass at Party.fr support The USD regression test files show no change in parse problems - 3 files still fail --- pyfpdb/PartyPokerToFpdb.py | 53 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/pyfpdb/PartyPokerToFpdb.py b/pyfpdb/PartyPokerToFpdb.py index 90d8e3b3..6eeefe1c 100755 --- a/pyfpdb/PartyPokerToFpdb.py +++ b/pyfpdb/PartyPokerToFpdb.py @@ -45,22 +45,27 @@ class PartyPoker(HandHistoryConverter): codepage = "utf8" siteId = 9 filetype = "text" - sym = {'USD': "\$", } + sym = {'USD': "\$", 'EUR': u"\u20ac", 'T$': ""} + currencies = {"\$": "USD", "$": "USD", u"\xe2\x82\xac": "EUR", u"\u20ac": "EUR", '': "T$"} + substitutions = { + 'LEGAL_ISO' : "USD|EUR", # legal ISO currency codes + 'LS' : "\$|\u20AC|\xe2\x82\xac|" # legal currency symbols - Euro(cp1252, utf-8) + } # Static regexes # $5 USD NL Texas Hold'em - Saturday, July 25, 07:53:52 EDT 2009 # NL Texas Hold'em $1 USD Buy-in Trny:45685440 Level:8 Blinds-Antes(600/1 200 -50) - Sunday, May 17, 11:25:07 MSKS 2009 - re_GameInfoRing = re.compile(""" - (?P\$|)\s*(?P[.,0-9]+)([.,0-9/$]+)?\s*(?:USD)?\s* + re_GameInfoRing = re.compile(u""" + (?P[%(LS)s])\s*(?P[.,0-9]+)([.,0-9/$]+)?\s*(?:%(LEGAL_ISO)s)?\s* (?P(NL|PL|))\s* (?P(Texas\ Hold\'em|Omaha|7 Card Stud Hi-Lo)) \s*\-\s* (?P.+) - """, re.VERBOSE | re.UNICODE) + """ % substitutions, re.VERBOSE | re.UNICODE) re_GameInfoTrny = re.compile(""" (?P(NL|PL|))\s* (?P(Texas\ Hold\'em|Omaha))\s+ - (?:(?P\$?[.,0-9]+)\s*(?PUSD)?\s*Buy-in\s+)? + (?:(?P\$?[.,0-9]+)\s*(?P%(LEGAL_ISO)s)?\s*Buy-in\s+)? Trny:\s?(?P\d+)\s+ Level:\s*(?P\d+)\s+ ((Blinds|Stakes)(?:-Antes)?)\( @@ -70,15 +75,14 @@ class PartyPoker(HandHistoryConverter): \) \s*\-\s* (?P.+) - """, re.VERBOSE | re.UNICODE) - re_Hid = re.compile("^Game \#(?P\d+) starts.") + """ % substitutions, re.VERBOSE | re.UNICODE) + re_Hid = re.compile("Game \#(?P\d+) starts.") - re_PlayerInfo = re.compile(""" + re_PlayerInfo = re.compile(u""" Seat\s(?P\d+):\s (?P.*)\s - \(\s*\$?(?P[0-9,.]+)\s*(?:USD|)\s*\) - """ , - re.VERBOSE) + \(\s*[%(LS)s]?(?P[0-9,.]+)\s*(?:%(LEGAL_ISO)s|)\s*\) + """ % substitutions, re.VERBOSE| re.UNICODE) re_HandInfo = re.compile(""" ^Table\s+(?P[$a-zA-Z0-9 ]+)?\s+ @@ -123,18 +127,16 @@ class PartyPoker(HandHistoryConverter): self.compiledPlayers = players player_re = "(?P" + "|".join(map(re.escape, players)) + ")" - subst = {'PLYR': player_re, 'CUR_SYM': hand.SYMBOL[hand.gametype['currency']], + subst = {'PLYR': player_re, 'CUR_SYM': self.sym[hand.gametype['currency']], 'CUR': hand.gametype['currency'] if hand.gametype['currency']!='T$' else ''} - for key in ('CUR_SYM', 'CUR'): - subst[key] = re.escape(subst[key]) self.re_PostSB = re.compile( - r"^%(PLYR)s posts small blind \[%(CUR_SYM)s(?P[.,0-9]+) ?%(CUR)s\]\." % subst, - re.MULTILINE) + r"^%(PLYR)s posts small blind \[%(CUR_SYM)s(?P[.,0-9]+) ?%(CUR)s\]\." + % subst, re.MULTILINE) self.re_PostBB = re.compile( - r"^%(PLYR)s posts big blind \[%(CUR_SYM)s(?P[.,0-9]+) ?%(CUR)s\]\." % subst, - re.MULTILINE) + u"%(PLYR)s posts big blind \[%(CUR_SYM)s(?P[.,0-9]+) ?%(CUR)s\]\." + % subst, re.MULTILINE) self.re_PostDead = re.compile( - r"^%(PLYR)s posts big blind \+ dead \[(?P[.,0-9]+) ?%(CUR_SYM)s\]\." % subst, + r"^%(PLYR)s posts big blind + dead \[(?P[.,0-9]+) ?%(CUR_SYM)s\]\." % subst, re.MULTILINE) self.re_Antes = re.compile( r"^%(PLYR)s posts ante \[%(CUR_SYM)s(?P[.,0-9]+) ?%(CUR)s\]" % subst, @@ -142,11 +144,10 @@ class PartyPoker(HandHistoryConverter): self.re_HeroCards = re.compile( r"^Dealt to %(PLYR)s \[\s*(?P.+)\s*\]" % subst, re.MULTILINE) - self.re_Action = re.compile(r""" + self.re_Action = re.compile(u""" ^%(PLYR)s\s+(?Pbets|checks|raises|calls|folds|is\sall-In) (?:\s+\[%(CUR_SYM)s(?P[.,\d]+)\s*%(CUR)s\])? - """ % subst, - re.MULTILINE|re.VERBOSE) + """ % subst, re.MULTILINE|re.VERBOSE) self.re_ShownCards = re.compile( r"^%s (?P(?:doesn\'t )?shows?) " % player_re + r"\[ *(?P.+) *\](?P.+)\.", @@ -205,7 +206,6 @@ class PartyPoker(HandHistoryConverter): 'Omaha' : ('hold','omahahi'), "7 Card Stud Hi-Lo" : ('stud','studhi'), } - currencies = { '$':'USD', '':'T$' } for expectedField in ['LIMIT', 'GAME']: if mg[expectedField] is None: @@ -238,7 +238,7 @@ class PartyPoker(HandHistoryConverter): info['bb'] = "%.2f" % (bb) info['sb'] = "%.2f" % (sb) - info['currency'] = currencies[mg['CURRENCY']] + info['currency'] = self.currencies[mg['CURRENCY']] else: info['sb'] = clearMoneyString(mg['SB']) info['bb'] = clearMoneyString(mg['BB']) @@ -251,8 +251,8 @@ class PartyPoker(HandHistoryConverter): info = {} try: info.update(self.re_Hid.search(hand.handText).groupdict()) - except: - raise FpdbParseError(_("Cannot read HID for current hand")) + except AttributeError, e: + raise FpdbParseError(_("Cannot read HID for current hand: %s" % e)) try: info.update(self.re_HandInfo.search(hand.handText,re.DOTALL).groupdict()) @@ -365,7 +365,6 @@ class PartyPoker(HandHistoryConverter): else: #zero stacked players are added later zeroStackPlayers.append([int(a.group('SEAT')), a.group('PNAME'), clearMoneyString(a.group('CASH'))]) - if hand.gametype['type'] == 'ring': #finds first vacant seat after an exact seat def findFirstEmptySeat(startSeat):