2009-08-06 15:14:52 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2010-07-04 03:05:16 +02:00
|
|
|
# Copyright 2009-2010, Grigorij Indigirkin
|
2009-08-12 00:35:34 +02:00
|
|
|
#
|
2009-08-06 15:14:52 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2009-08-12 00:35:34 +02:00
|
|
|
#
|
2009-08-06 15:14:52 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2009-08-12 00:35:34 +02:00
|
|
|
#
|
2009-08-06 15:14:52 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
########################################################################
|
|
|
|
|
2010-09-23 08:31:16 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
import sys
|
|
|
|
from collections import defaultdict
|
|
|
|
|
2010-11-03 17:54:03 +01:00
|
|
|
from Configuration import LOCALE_ENCODING
|
2009-08-10 16:13:39 +02:00
|
|
|
from Exceptions import FpdbParseError
|
2009-08-06 15:14:52 +02:00
|
|
|
from HandHistoryConverter import *
|
|
|
|
|
|
|
|
# PartyPoker HH Format
|
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
class FpdbParseError(FpdbParseError):
|
|
|
|
"Usage: raise FpdbParseError(<msg>[, hh=<hh>][, hid=<hid>])"
|
2009-10-31 15:53:31 +01:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
def __init__(self, msg='', hh=None, hid=None):
|
2009-11-08 21:09:14 +01:00
|
|
|
return super(FpdbParseError, self).__init__(msg, hid=hid)
|
2009-10-31 15:53:31 +01:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
def wrapHh(self, hh):
|
|
|
|
return ("%(DELIMETER)s\n%(HH)s\n%(DELIMETER)s") % \
|
|
|
|
{'DELIMETER': '#'*50, 'HH': hh}
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
class PartyPoker(HandHistoryConverter):
|
2009-08-09 21:22:23 +02:00
|
|
|
sitename = "PartyPoker"
|
2010-11-03 17:54:03 +01:00
|
|
|
codepage = "utf8"
|
2010-08-12 10:46:23 +02:00
|
|
|
siteId = 9
|
|
|
|
filetype = "text"
|
2010-12-02 10:40:24 +01:00
|
|
|
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
|
2011-02-06 04:48:07 +01:00
|
|
|
'LS' : u"\$|\u20ac|\xe2\x82\xac|", # Currency symbols - Euro(cp1252, utf-8)
|
|
|
|
'NUM' : u".,\d",
|
2010-12-02 10:40:24 +01:00
|
|
|
}
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
# 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
|
2010-12-02 10:40:24 +01:00
|
|
|
re_GameInfoRing = re.compile(u"""
|
|
|
|
(?P<CURRENCY>[%(LS)s])\s*(?P<RINGLIMIT>[.,0-9]+)([.,0-9/$]+)?\s*(?:%(LEGAL_ISO)s)?\s*
|
2010-01-23 16:24:00 +01:00
|
|
|
(?P<LIMIT>(NL|PL|))\s*
|
2010-12-03 11:13:07 +01:00
|
|
|
(?P<GAME>(Texas\ Hold\'em|Omaha|7\ Card\ Stud\ Hi-Lo))
|
2009-08-06 15:14:52 +02:00
|
|
|
\s*\-\s*
|
|
|
|
(?P<DATETIME>.+)
|
2010-12-02 10:40:24 +01:00
|
|
|
""" % substitutions, re.VERBOSE | re.UNICODE)
|
2009-08-06 15:14:52 +02:00
|
|
|
re_GameInfoTrny = re.compile("""
|
2010-01-23 16:24:00 +01:00
|
|
|
(?P<LIMIT>(NL|PL|))\s*
|
2009-08-09 17:54:35 +02:00
|
|
|
(?P<GAME>(Texas\ Hold\'em|Omaha))\s+
|
2010-12-02 10:40:24 +01:00
|
|
|
(?:(?P<BUYIN>\$?[.,0-9]+)\s*(?P<BUYIN_CURRENCY>%(LEGAL_ISO)s)?\s*Buy-in\s+)?
|
2009-08-06 15:14:52 +02:00
|
|
|
Trny:\s?(?P<TOURNO>\d+)\s+
|
|
|
|
Level:\s*(?P<LEVEL>\d+)\s+
|
2010-01-23 16:24:00 +01:00
|
|
|
((Blinds|Stakes)(?:-Antes)?)\(
|
|
|
|
(?P<SB>[.,0-9 ]+)\s*
|
|
|
|
/(?P<BB>[.,0-9 ]+)
|
|
|
|
(?:\s*-\s*(?P<ANTE>[.,0-9 ]+)\$?)?
|
2009-08-06 15:14:52 +02:00
|
|
|
\)
|
|
|
|
\s*\-\s*
|
|
|
|
(?P<DATETIME>.+)
|
2010-12-02 10:40:24 +01:00
|
|
|
""" % substitutions, re.VERBOSE | re.UNICODE)
|
|
|
|
re_Hid = re.compile("Game \#(?P<HID>\d+) starts.")
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2010-12-02 10:40:24 +01:00
|
|
|
re_PlayerInfo = re.compile(u"""
|
2009-08-06 15:14:52 +02:00
|
|
|
Seat\s(?P<SEAT>\d+):\s
|
|
|
|
(?P<PNAME>.*)\s
|
2011-02-06 04:48:07 +01:00
|
|
|
\(\s*[%(LS)s]?(?P<CASH>[%(NUM)s]+)\s*(?:%(LEGAL_ISO)s|)\s*\)
|
2010-12-02 10:40:24 +01:00
|
|
|
""" % substitutions, re.VERBOSE| re.UNICODE)
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
re_HandInfo = re.compile("""
|
2010-03-03 18:57:30 +01:00
|
|
|
^Table\s+(?P<TTYPE>[$a-zA-Z0-9 ]+)?\s+
|
2009-08-06 15:14:52 +02:00
|
|
|
(?: \#|\(|)(?P<TABLE>\d+)\)?\s+
|
2010-01-23 16:24:00 +01:00
|
|
|
(?:[a-zA-Z0-9 ]+\s+\#(?P<MTTTABLE>\d+).+)?
|
2009-12-21 02:21:41 +01:00
|
|
|
(\(No\sDP\)\s)?
|
2009-08-06 15:14:52 +02:00
|
|
|
\((?P<PLAY>Real|Play)\s+Money\)\s+ # FIXME: check if play money is correct
|
|
|
|
Seat\s+(?P<BUTTON>\d+)\sis\sthe\sbutton
|
2010-03-03 06:42:13 +01:00
|
|
|
\s+Total\s+number\s+of\s+players\s+\:\s+(?P<PLYRS>\d+)/?(?P<MAX>\d+)?
|
2009-08-12 00:35:34 +02:00
|
|
|
""",
|
2010-03-03 06:42:13 +01:00
|
|
|
re.VERBOSE|re.MULTILINE|re.DOTALL)
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
re_CountedSeats = re.compile("^Total\s+number\s+of\s+players\s*:\s*(?P<COUNTED_SEATS>\d+)", re.MULTILINE)
|
2009-08-06 15:14:52 +02:00
|
|
|
re_SplitHands = re.compile('\x00+')
|
|
|
|
re_TailSplitHands = re.compile('(\x00+)')
|
|
|
|
lineSplitter = '\n'
|
|
|
|
re_Button = re.compile('Seat (?P<BUTTON>\d+) is the button', re.MULTILINE)
|
|
|
|
re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
|
2009-08-11 16:02:58 +02:00
|
|
|
re_NoSmallBlind = re.compile(
|
|
|
|
'^There is no Small Blind in this hand as the Big Blind '
|
|
|
|
'of the previous hand left the table', re.MULTILINE)
|
2010-08-12 10:46:23 +02:00
|
|
|
re_20BBmin = re.compile(r"Table 20BB Min")
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def allHandsAsList(self):
|
|
|
|
list = HandHistoryConverter.allHandsAsList(self)
|
2009-08-09 14:38:55 +02:00
|
|
|
if list is None:
|
2009-08-09 19:24:48 +02:00
|
|
|
return []
|
2009-08-06 15:14:52 +02:00
|
|
|
return filter(lambda text: len(text.strip()), list)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-09 19:24:48 +02:00
|
|
|
def guessMaxSeats(self, hand):
|
|
|
|
"""Return a guess at max_seats when not specified in HH."""
|
2010-03-03 21:08:00 +01:00
|
|
|
mo = self.maxOccSeat(hand)
|
|
|
|
if mo == 10: return mo
|
|
|
|
if mo == 2: return 2
|
|
|
|
if mo <= 6: return 6
|
|
|
|
# there are 9-max tables for cash and 10-max for tournaments
|
|
|
|
return 9 if hand.gametype['type']=='ring' else 10
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def compilePlayerRegexs(self, hand):
|
|
|
|
players = set([player[1] for player in hand.players])
|
|
|
|
if not players <= self.compiledPlayers: # x <= y means 'x is subset of y'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
self.compiledPlayers = players
|
|
|
|
player_re = "(?P<PNAME>" + "|".join(map(re.escape, players)) + ")"
|
2010-12-02 10:40:24 +01:00
|
|
|
subst = {'PLYR': player_re, 'CUR_SYM': self.sym[hand.gametype['currency']],
|
2009-08-06 15:14:52 +02:00
|
|
|
'CUR': hand.gametype['currency'] if hand.gametype['currency']!='T$' else ''}
|
|
|
|
self.re_PostSB = re.compile(
|
2010-12-02 10:40:24 +01:00
|
|
|
r"^%(PLYR)s posts small blind \[%(CUR_SYM)s(?P<SB>[.,0-9]+) ?%(CUR)s\]\."
|
|
|
|
% subst, re.MULTILINE)
|
2009-08-06 15:14:52 +02:00
|
|
|
self.re_PostBB = re.compile(
|
2010-12-02 10:40:24 +01:00
|
|
|
u"%(PLYR)s posts big blind \[%(CUR_SYM)s(?P<BB>[.,0-9]+) ?%(CUR)s\]\."
|
|
|
|
% subst, re.MULTILINE)
|
2009-08-11 16:02:58 +02:00
|
|
|
self.re_PostDead = re.compile(
|
2010-12-02 10:40:24 +01:00
|
|
|
r"^%(PLYR)s posts big blind + dead \[(?P<BBNDEAD>[.,0-9]+) ?%(CUR_SYM)s\]\." % subst,
|
2009-08-11 16:02:58 +02:00
|
|
|
re.MULTILINE)
|
2009-08-06 15:14:52 +02:00
|
|
|
self.re_Antes = re.compile(
|
2010-01-23 16:24:00 +01:00
|
|
|
r"^%(PLYR)s posts ante \[%(CUR_SYM)s(?P<ANTE>[.,0-9]+) ?%(CUR)s\]" % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
self.re_HeroCards = re.compile(
|
|
|
|
r"^Dealt to %(PLYR)s \[\s*(?P<NEWCARDS>.+)\s*\]" % subst,
|
|
|
|
re.MULTILINE)
|
2010-12-02 10:40:24 +01:00
|
|
|
self.re_Action = re.compile(u"""
|
2009-08-06 15:14:52 +02:00
|
|
|
^%(PLYR)s\s+(?P<ATYPE>bets|checks|raises|calls|folds|is\sall-In)
|
|
|
|
(?:\s+\[%(CUR_SYM)s(?P<BET>[.,\d]+)\s*%(CUR)s\])?
|
2010-12-02 10:40:24 +01:00
|
|
|
""" % subst, re.MULTILINE|re.VERBOSE)
|
2009-08-06 15:14:52 +02:00
|
|
|
self.re_ShownCards = re.compile(
|
2009-08-12 00:35:34 +02:00
|
|
|
r"^%s (?P<SHOWED>(?:doesn\'t )?shows?) " % player_re +
|
|
|
|
r"\[ *(?P<CARDS>.+) *\](?P<COMBINATION>.+)\.",
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
self.re_CollectPot = re.compile(
|
2009-08-10 16:13:39 +02:00
|
|
|
r"""^%(PLYR)s \s+ wins \s+
|
2009-08-12 00:35:34 +02:00
|
|
|
%(CUR_SYM)s(?P<POT>[.,\d]+)\s*%(CUR)s""" % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE|re.VERBOSE)
|
|
|
|
|
|
|
|
def readSupportedGames(self):
|
|
|
|
return [["ring", "hold", "nl"],
|
2009-08-09 17:54:35 +02:00
|
|
|
["ring", "hold", "pl"],
|
|
|
|
["ring", "hold", "fl"],
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
["tour", "hold", "nl"],
|
2009-08-09 17:54:35 +02:00
|
|
|
["tour", "hold", "pl"],
|
|
|
|
["tour", "hold", "fl"],
|
2009-08-06 15:14:52 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def _getGameType(self, handText):
|
2009-08-09 23:45:55 +02:00
|
|
|
if not hasattr(self, '_gameType'):
|
|
|
|
self._gameType = None
|
2009-08-06 15:14:52 +02:00
|
|
|
if self._gameType is None:
|
|
|
|
# let's determine whether hand is trny
|
|
|
|
# and whether 5-th line contains head line
|
|
|
|
headLine = handText.split(self.lineSplitter)[4]
|
|
|
|
for headLineContainer in headLine, handText:
|
|
|
|
for regexp in self.re_GameInfoTrny, self.re_GameInfoRing:
|
|
|
|
m = regexp.search(headLineContainer)
|
|
|
|
if m is not None:
|
|
|
|
self._gameType = m
|
|
|
|
return self._gameType
|
|
|
|
return self._gameType
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def determineGameType(self, handText):
|
2009-08-06 15:55:53 +02:00
|
|
|
"""inspect the handText and return the gametype dict
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:55:53 +02:00
|
|
|
gametype dict is:
|
|
|
|
{'limitType': xxx, 'base': xxx, 'category': xxx}"""
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
info = {}
|
|
|
|
m = self._getGameType(handText)
|
2010-08-12 10:46:23 +02:00
|
|
|
m_20BBmin = self.re_20BBmin.search(handText)
|
2009-08-06 15:14:52 +02:00
|
|
|
if m is None:
|
2010-09-06 10:44:08 +02:00
|
|
|
tmp = handText[0:100]
|
|
|
|
log.error(_("determineGameType: Unable to recognise gametype from: '%s'") % tmp)
|
|
|
|
log.error(_("determineGameType: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp)
|
2009-08-06 15:14:52 +02:00
|
|
|
return None
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
mg = m.groupdict()
|
|
|
|
# translations from captured groups to fpdb info strings
|
2009-08-09 17:54:35 +02:00
|
|
|
limits = { 'NL':'nl', 'PL':'pl', '':'fl' }
|
2009-08-06 15:14:52 +02:00
|
|
|
games = { # base, category
|
2009-08-12 00:35:34 +02:00
|
|
|
"Texas Hold'em" : ('hold','holdem'),
|
2009-08-09 17:54:35 +02:00
|
|
|
'Omaha' : ('hold','omahahi'),
|
2010-09-28 16:47:04 +02:00
|
|
|
"7 Card Stud Hi-Lo" : ('stud','studhi'),
|
2009-08-06 15:14:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for expectedField in ['LIMIT', 'GAME']:
|
|
|
|
if mg[expectedField] is None:
|
2010-08-16 03:28:17 +02:00
|
|
|
raise FpdbParseError(_("Cannot fetch field '%s'") % expectedField)
|
2009-08-06 15:14:52 +02:00
|
|
|
try:
|
2009-08-09 17:54:35 +02:00
|
|
|
info['limitType'] = limits[mg['LIMIT'].strip()]
|
2009-08-06 15:14:52 +02:00
|
|
|
except:
|
2010-08-16 03:28:17 +02:00
|
|
|
raise FpdbParseError(_("Unknown limit '%s'") % mg['LIMIT'])
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
(info['base'], info['category']) = games[mg['GAME']]
|
|
|
|
except:
|
2010-08-16 03:28:17 +02:00
|
|
|
raise FpdbParseError(_("Unknown game type '%s'") % mg['GAME'])
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
if 'TOURNO' in mg:
|
|
|
|
info['type'] = 'tour'
|
|
|
|
else:
|
|
|
|
info['type'] = 'ring'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
if info['type'] == 'ring':
|
2010-08-12 10:46:23 +02:00
|
|
|
if m_20BBmin is None:
|
|
|
|
bb = float(mg['RINGLIMIT'])/100.0
|
2010-08-10 00:36:34 +02:00
|
|
|
else:
|
2010-08-12 10:46:23 +02:00
|
|
|
bb = float(mg['RINGLIMIT'])/40.0
|
|
|
|
|
|
|
|
if bb == 0.25:
|
|
|
|
sb = 0.10
|
|
|
|
else:
|
|
|
|
sb = bb/2.0
|
|
|
|
|
|
|
|
info['bb'] = "%.2f" % (bb)
|
|
|
|
info['sb'] = "%.2f" % (sb)
|
2010-12-02 10:40:24 +01:00
|
|
|
info['currency'] = self.currencies[mg['CURRENCY']]
|
2009-08-06 15:14:52 +02:00
|
|
|
else:
|
2010-12-20 07:00:09 +01:00
|
|
|
info['sb'] = self.clearMoneyString(mg['SB'])
|
|
|
|
info['bb'] = self.clearMoneyString(mg['BB'])
|
2009-08-06 15:14:52 +02:00
|
|
|
info['currency'] = 'T$'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
def readHandInfo(self, hand):
|
|
|
|
info = {}
|
2009-08-10 16:13:39 +02:00
|
|
|
try:
|
|
|
|
info.update(self.re_Hid.search(hand.handText).groupdict())
|
2010-12-02 10:40:24 +01:00
|
|
|
except AttributeError, e:
|
|
|
|
raise FpdbParseError(_("Cannot read HID for current hand: %s" % e))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
try:
|
|
|
|
info.update(self.re_HandInfo.search(hand.handText,re.DOTALL).groupdict())
|
|
|
|
except:
|
2010-08-16 03:28:17 +02:00
|
|
|
raise FpdbParseError(_("Cannot read Handinfo for current hand"), hid = info['HID'])
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
try:
|
|
|
|
info.update(self._getGameType(hand.handText).groupdict())
|
|
|
|
except:
|
2010-08-16 03:28:17 +02:00
|
|
|
raise FpdbParseError(_("Cannot read GameType for current hand"), hid = info['HID'])
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
m = self.re_CountedSeats.search(hand.handText)
|
|
|
|
if m: info.update(m.groupdict())
|
2009-08-09 14:38:55 +02:00
|
|
|
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-11 16:02:58 +02:00
|
|
|
# FIXME: it's dirty hack
|
|
|
|
# party doesnt subtract uncalled money from commited money
|
|
|
|
# so hand.totalPot calculation has to be redefined
|
|
|
|
from Hand import Pot, HoldemOmahaHand
|
|
|
|
def getNewTotalPot(origTotalPot):
|
|
|
|
def totalPot(self):
|
|
|
|
if self.totalpot is None:
|
|
|
|
self.pot.end()
|
|
|
|
self.totalpot = self.pot.total
|
|
|
|
for i,v in enumerate(self.collected):
|
|
|
|
if v[0] in self.pot.returned:
|
|
|
|
self.collected[i][1] = Decimal(v[1]) - self.pot.returned[v[0]]
|
2010-03-02 21:44:07 +01:00
|
|
|
self.collectees[v[0]] -= self.pot.returned[v[0]]
|
2010-03-04 14:11:50 +01:00
|
|
|
self.pot.returned[v[0]] = 0
|
2009-08-11 16:02:58 +02:00
|
|
|
return origTotalPot()
|
|
|
|
return totalPot
|
|
|
|
instancemethod = type(hand.totalPot)
|
|
|
|
hand.totalPot = instancemethod(getNewTotalPot(hand.totalPot), hand, HoldemOmahaHand)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-09 21:22:23 +02:00
|
|
|
log.debug("readHandInfo: %s" % info)
|
2009-08-06 15:14:52 +02:00
|
|
|
for key in info:
|
|
|
|
if key == 'DATETIME':
|
|
|
|
#Saturday, July 25, 07:53:52 EDT 2009
|
|
|
|
#Thursday, July 30, 21:40:41 MSKS 2009
|
2009-11-08 21:09:14 +01:00
|
|
|
#Sunday, October 25, 13:39:07 MSK 2009
|
2010-11-03 17:54:03 +01:00
|
|
|
m2 = re.search(
|
|
|
|
r"\w+,\s+(?P<M>\w+)\s+(?P<D>\d+),\s+(?P<H>\d+):(?P<MIN>\d+):(?P<S>\d+)\s+(?P<TZ>[A-Z]+)\s+(?P<Y>\d+)",
|
|
|
|
info[key],
|
|
|
|
re.UNICODE
|
|
|
|
)
|
2009-08-06 15:14:52 +02:00
|
|
|
months = ['January', 'February', 'March', 'April','May', 'June',
|
|
|
|
'July','August','September','October','November','December']
|
2010-11-03 17:54:03 +01:00
|
|
|
if m2.group('M') not in months:
|
|
|
|
raise FpdbParseError("Only english hh is supported", hid=info["HID"])
|
2009-08-06 15:14:52 +02:00
|
|
|
month = months.index(m2.group('M')) + 1
|
|
|
|
datetimestr = "%s/%s/%s %s:%s:%s" % (m2.group('Y'), month,m2.group('D'),m2.group('H'),m2.group('MIN'),m2.group('S'))
|
2010-07-08 17:30:02 +02:00
|
|
|
hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
|
2009-08-06 15:55:53 +02:00
|
|
|
# FIXME: some timezone correction required
|
2009-08-06 15:14:52 +02:00
|
|
|
#tzShift = defaultdict(lambda:0, {'EDT': -5, 'EST': -6, 'MSKS': 3})
|
|
|
|
#hand.starttime -= datetime.timedelta(hours=tzShift[m2.group('TZ')])
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'HID':
|
|
|
|
hand.handid = info[key]
|
|
|
|
if key == 'TABLE':
|
|
|
|
hand.tablename = info[key]
|
2010-01-23 16:24:00 +01:00
|
|
|
if key == 'MTTTABLE':
|
2010-08-12 10:46:23 +02:00
|
|
|
if info[key] != None:
|
|
|
|
hand.tablename = info[key]
|
|
|
|
hand.tourNo = info['TABLE']
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'BUTTON':
|
|
|
|
hand.buttonpos = info[key]
|
|
|
|
if key == 'TOURNO':
|
|
|
|
hand.tourNo = info[key]
|
2009-11-08 21:09:14 +01:00
|
|
|
if key == 'TABLE_ID_WRAPPER':
|
|
|
|
if info[key] == '#':
|
|
|
|
# FIXME: there is no such property in Hand class
|
|
|
|
self.isSNG = True
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'BUYIN':
|
2011-02-10 11:45:12 +01:00
|
|
|
if hand.tourNo != None:
|
|
|
|
hand.buyin = 0
|
|
|
|
hand.fee = 0
|
|
|
|
hand.buyinCurrency = "FREE"
|
|
|
|
hand.isKO = False
|
|
|
|
if info[key].find("$")!=-1:
|
|
|
|
hand.buyinCurrency="USD"
|
|
|
|
elif info[key].find(u"€")!=-1:
|
|
|
|
hand.buyinCurrency="EUR"
|
|
|
|
else:
|
|
|
|
raise FpdbParseError(_("Failed to detect currency. HID: %s: '%s'" % (hand.handid, info[key])))
|
|
|
|
info[key] = info[key].strip(u'$€')
|
|
|
|
hand.buyin = int(100*Decimal(info[key]))
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'LEVEL':
|
|
|
|
hand.level = info[key]
|
|
|
|
if key == 'PLAY' and info['PLAY'] != 'Real':
|
2009-11-08 21:09:14 +01:00
|
|
|
# if realy party doesn's save play money hh
|
2009-08-06 15:14:52 +02:00
|
|
|
hand.gametype['currency'] = 'play'
|
2010-03-03 19:05:06 +01:00
|
|
|
if key == 'MAX' and info[key] is not None:
|
2010-03-03 06:42:13 +01:00
|
|
|
hand.maxseats = int(info[key])
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readButton(self, hand):
|
|
|
|
m = self.re_Button.search(hand.handText)
|
|
|
|
if m:
|
|
|
|
hand.buttonpos = int(m.group('BUTTON'))
|
|
|
|
else:
|
2010-08-16 03:28:17 +02:00
|
|
|
log.info(_('readButton: not found'))
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readPlayerStacks(self, hand):
|
2009-08-09 21:22:23 +02:00
|
|
|
log.debug("readPlayerStacks")
|
2009-08-06 15:14:52 +02:00
|
|
|
m = self.re_PlayerInfo.finditer(hand.handText)
|
2010-09-28 15:46:51 +02:00
|
|
|
maxKnownStack = 0
|
|
|
|
zeroStackPlayers = []
|
2009-08-06 15:14:52 +02:00
|
|
|
for a in m:
|
2010-09-28 15:46:51 +02:00
|
|
|
if a.group('CASH') > '0':
|
|
|
|
#record max known stack for use with players with unknown stack
|
|
|
|
maxKnownStack = max(a.group('CASH'),maxKnownStack)
|
2010-12-20 07:00:09 +01:00
|
|
|
hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), self.clearMoneyString(a.group('CASH')))
|
2010-09-28 15:46:51 +02:00
|
|
|
else:
|
|
|
|
#zero stacked players are added later
|
2010-12-20 07:00:09 +01:00
|
|
|
zeroStackPlayers.append([int(a.group('SEAT')), a.group('PNAME'), self.clearMoneyString(a.group('CASH'))])
|
2010-09-10 21:54:10 +02:00
|
|
|
if hand.gametype['type'] == 'ring':
|
2010-09-28 15:46:51 +02:00
|
|
|
#finds first vacant seat after an exact seat
|
2010-09-10 21:54:10 +02:00
|
|
|
def findFirstEmptySeat(startSeat):
|
|
|
|
while startSeat in occupiedSeats:
|
|
|
|
if startSeat >= hand.maxseats:
|
|
|
|
startSeat = 0
|
|
|
|
startSeat += 1
|
|
|
|
return startSeat
|
|
|
|
|
2010-09-28 15:46:51 +02:00
|
|
|
re_JoiningPlayers = re.compile(r"(?P<PLAYERNAME>.*) has joined the table")
|
|
|
|
re_BBPostingPlayers = re.compile(r"(?P<PLAYERNAME>.*) posts big blind")
|
|
|
|
|
2010-09-10 21:54:10 +02:00
|
|
|
match_JoiningPlayers = re_JoiningPlayers.findall(hand.handText)
|
|
|
|
match_BBPostingPlayers = re_BBPostingPlayers.findall(hand.handText)
|
|
|
|
|
2010-09-28 15:46:51 +02:00
|
|
|
#add every player with zero stack, but:
|
|
|
|
#if a zero stacked player is just joined the table in this very hand then set his stack to maxKnownStack
|
|
|
|
for p in zeroStackPlayers:
|
|
|
|
if p[1] in match_JoiningPlayers:
|
2010-12-20 07:00:09 +01:00
|
|
|
p[2] = self.clearMoneyString(maxKnownStack)
|
2010-09-28 15:46:51 +02:00
|
|
|
hand.addPlayer(p[0],p[1],p[2])
|
|
|
|
|
|
|
|
seatedPlayers = list([(f[1]) for f in hand.players])
|
|
|
|
|
|
|
|
#it works for all known cases as of 2010-09-28
|
|
|
|
#should be refined with using match_ActivePlayers instead of match_BBPostingPlayers
|
|
|
|
#as a leaving and rejoining player could be active without posting a BB (sample HH needed)
|
|
|
|
unseatedActivePlayers = list(set(match_BBPostingPlayers) - set(seatedPlayers))
|
2010-09-10 21:54:10 +02:00
|
|
|
|
|
|
|
if unseatedActivePlayers:
|
|
|
|
for player in unseatedActivePlayers:
|
|
|
|
previousBBPoster = match_BBPostingPlayers[match_BBPostingPlayers.index(player)-1]
|
|
|
|
previousBBPosterSeat = dict([(f[1], f[0]) for f in hand.players])[previousBBPoster]
|
|
|
|
occupiedSeats = list([(f[0]) for f in hand.players])
|
|
|
|
occupiedSeats.sort()
|
|
|
|
newPlayerSeat = findFirstEmptySeat(previousBBPosterSeat)
|
2010-12-20 07:00:09 +01:00
|
|
|
hand.addPlayer(newPlayerSeat,player,self.clearMoneyString(maxKnownStack))
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def markStreets(self, hand):
|
|
|
|
m = re.search(
|
|
|
|
r"\*{2} Dealing down cards \*{2}"
|
|
|
|
r"(?P<PREFLOP>.+?)"
|
|
|
|
r"(?:\*{2} Dealing Flop \*{2} (?P<FLOP>\[ \S\S, \S\S, \S\S \].+?))?"
|
|
|
|
r"(?:\*{2} Dealing Turn \*{2} (?P<TURN>\[ \S\S \].+?))?"
|
|
|
|
r"(?:\*{2} Dealing River \*{2} (?P<RIVER>\[ \S\S \].+?))?$"
|
|
|
|
, hand.handText,re.DOTALL)
|
|
|
|
hand.addStreets(m)
|
|
|
|
|
2009-08-12 00:35:34 +02:00
|
|
|
def readCommunityCards(self, hand, street):
|
|
|
|
if street in ('FLOP','TURN','RIVER'):
|
2009-08-06 15:14:52 +02:00
|
|
|
m = self.re_Board.search(hand.streets[street])
|
|
|
|
hand.setCommunityCards(street, renderCards(m.group('CARDS')))
|
|
|
|
|
|
|
|
def readAntes(self, hand):
|
2009-08-09 21:22:23 +02:00
|
|
|
log.debug("reading antes")
|
2009-08-06 15:14:52 +02:00
|
|
|
m = self.re_Antes.finditer(hand.handText)
|
|
|
|
for player in m:
|
|
|
|
hand.addAnte(player.group('PNAME'), player.group('ANTE'))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def readBlinds(self, hand):
|
|
|
|
noSmallBlind = bool(self.re_NoSmallBlind.search(hand.handText))
|
|
|
|
if hand.gametype['type'] == 'ring':
|
|
|
|
try:
|
|
|
|
assert noSmallBlind==False
|
2010-03-04 19:49:43 +01:00
|
|
|
liveBlind = True
|
|
|
|
for m in self.re_PostSB.finditer(hand.handText):
|
|
|
|
if liveBlind:
|
|
|
|
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
|
|
|
|
liveBlind = False
|
|
|
|
else:
|
|
|
|
# Post dead blinds as ante
|
|
|
|
hand.addBlind(m.group('PNAME'), 'secondsb', m.group('SB'))
|
2009-08-06 15:14:52 +02:00
|
|
|
except: # no small blind
|
|
|
|
hand.addBlind(None, None, None)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
for a in self.re_PostBB.finditer(hand.handText):
|
|
|
|
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-11 16:02:58 +02:00
|
|
|
deadFilter = lambda s: s.replace(',', '.')
|
|
|
|
for a in self.re_PostDead.finditer(hand.handText):
|
|
|
|
hand.addBlind(a.group('PNAME'), 'both', deadFilter(a.group('BBNDEAD')))
|
2009-08-12 00:35:34 +02:00
|
|
|
else:
|
2009-08-06 15:14:52 +02:00
|
|
|
# party doesn't track blinds for tournaments
|
|
|
|
# so there're some cra^Wcaclulations
|
|
|
|
if hand.buttonpos == 0:
|
|
|
|
self.readButton(hand)
|
|
|
|
# NOTE: code below depends on Hand's implementation
|
|
|
|
# playersMap - dict {seat: (pname,stack)}
|
2009-08-12 00:35:34 +02:00
|
|
|
playersMap = dict([(f[0], f[1:3]) for f in hand.players])
|
2009-08-06 15:14:52 +02:00
|
|
|
maxSeat = max(playersMap)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def findFirstNonEmptySeat(startSeat):
|
|
|
|
while startSeat not in playersMap:
|
2009-08-12 00:35:34 +02:00
|
|
|
if startSeat >= maxSeat:
|
2009-08-06 15:14:52 +02:00
|
|
|
startSeat = 0
|
|
|
|
startSeat += 1
|
|
|
|
return startSeat
|
|
|
|
smartMin = lambda A,B: A if float(A) <= float(B) else B
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
if noSmallBlind:
|
|
|
|
hand.addBlind(None, None, None)
|
2009-08-11 16:02:58 +02:00
|
|
|
smallBlindSeat = int(hand.buttonpos)
|
2009-08-06 15:14:52 +02:00
|
|
|
else:
|
|
|
|
smallBlindSeat = findFirstNonEmptySeat(int(hand.buttonpos) + 1)
|
|
|
|
blind = smartMin(hand.sb, playersMap[smallBlindSeat][1])
|
|
|
|
hand.addBlind(playersMap[smallBlindSeat][0], 'small blind', blind)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
bigBlindSeat = findFirstNonEmptySeat(smallBlindSeat + 1)
|
|
|
|
blind = smartMin(hand.bb, playersMap[bigBlindSeat][1])
|
2009-08-10 16:13:39 +02:00
|
|
|
hand.addBlind(playersMap[bigBlindSeat][0], 'big blind', blind)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def readHeroCards(self, hand):
|
2009-08-06 15:55:53 +02:00
|
|
|
# we need to grab hero's cards
|
2009-08-06 15:14:52 +02:00
|
|
|
for street in ('PREFLOP',):
|
|
|
|
if street in hand.streets.keys():
|
|
|
|
m = self.re_HeroCards.finditer(hand.streets[street])
|
|
|
|
for found in m:
|
|
|
|
hand.hero = found.group('PNAME')
|
|
|
|
newcards = renderCards(found.group('NEWCARDS'))
|
|
|
|
hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
|
|
|
|
|
|
|
|
def readAction(self, hand, street):
|
|
|
|
m = self.re_Action.finditer(hand.streets[street])
|
|
|
|
for action in m:
|
|
|
|
acts = action.groupdict()
|
2009-08-10 16:13:39 +02:00
|
|
|
playerName = action.group('PNAME')
|
2010-12-20 07:00:09 +01:00
|
|
|
amount = self.clearMoneyString(action.group('BET')) if action.group('BET') else None
|
2009-08-10 16:13:39 +02:00
|
|
|
actionType = action.group('ATYPE')
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
if actionType == 'is all-In':
|
|
|
|
# party's allin can mean either raise or bet or call
|
|
|
|
Bp = hand.lastBet[street]
|
|
|
|
if Bp == 0:
|
|
|
|
actionType = 'bets'
|
|
|
|
elif Bp < Decimal(amount):
|
|
|
|
actionType = 'raises'
|
|
|
|
else:
|
|
|
|
actionType = 'calls'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
if actionType == 'raises':
|
|
|
|
if street == 'PREFLOP' and \
|
2009-08-12 09:18:42 +02:00
|
|
|
playerName in [item[0] for item in hand.actions['BLINDSANTES'] if item[2]!='ante']:
|
2009-08-10 16:13:39 +02:00
|
|
|
# preflop raise from blind
|
2010-03-04 14:32:48 +01:00
|
|
|
hand.addCallandRaise( street, playerName, amount )
|
2009-08-10 16:13:39 +02:00
|
|
|
else:
|
|
|
|
hand.addCallandRaise( street, playerName, amount )
|
|
|
|
elif actionType == 'calls':
|
|
|
|
hand.addCall( street, playerName, amount )
|
|
|
|
elif actionType == 'bets':
|
|
|
|
hand.addBet( street, playerName, amount )
|
|
|
|
elif actionType == 'folds':
|
|
|
|
hand.addFold( street, playerName )
|
|
|
|
elif actionType == 'checks':
|
|
|
|
hand.addCheck( street, playerName )
|
2009-08-06 15:14:52 +02:00
|
|
|
else:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError(
|
2010-08-16 03:28:17 +02:00
|
|
|
_("Unimplemented readAction: '%s' '%s'") % (playerName,actionType,),
|
2009-11-08 21:09:14 +01:00
|
|
|
hid = hand.hid, )
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readShowdownActions(self, hand):
|
|
|
|
# all action in readShownCards
|
|
|
|
pass
|
|
|
|
|
|
|
|
def readCollectPot(self,hand):
|
|
|
|
for m in self.re_CollectPot.finditer(hand.handText):
|
2010-12-20 07:00:09 +01:00
|
|
|
hand.addCollectPot(player=m.group('PNAME'),pot=self.clearMoneyString(m.group('POT')))
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readShownCards(self,hand):
|
|
|
|
for m in self.re_ShownCards.finditer(hand.handText):
|
|
|
|
if m.group('CARDS') is not None:
|
|
|
|
cards = renderCards(m.group('CARDS'))
|
|
|
|
|
2009-10-31 15:53:31 +01:00
|
|
|
mucked = m.group('SHOWED') != "show"
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2009-10-31 15:53:31 +01:00
|
|
|
hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=True, mucked=mucked)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
@staticmethod
|
|
|
|
def getTableTitleRe(type, table_name=None, tournament = None, table_number=None):
|
|
|
|
"Returns string to search in windows titles"
|
|
|
|
if type=="tour":
|
2010-02-13 22:44:00 +01:00
|
|
|
TableName = table_name.split(" ")
|
|
|
|
print 'party', 'getTableTitleRe', "%s.+Table\s#%s" % (TableName[0], table_number)
|
2010-08-28 15:25:41 +02:00
|
|
|
if len(TableName[1]) > 6:
|
|
|
|
return "#%s" % (table_number)
|
2010-08-27 16:53:33 +02:00
|
|
|
else:
|
|
|
|
return "%s.+Table\s#%s" % (TableName[0], table_number)
|
2009-11-08 21:09:14 +01:00
|
|
|
else:
|
|
|
|
return table_name
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def renderCards(string):
|
2009-08-10 16:13:39 +02:00
|
|
|
"Splits strings like ' Js, 4d '"
|
2009-08-06 15:14:52 +02:00
|
|
|
cards = string.strip().split(' ')
|
|
|
|
return filter(len, map(lambda x: x.strip(' ,'), cards))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = OptionParser()
|
2010-08-16 03:28:17 +02:00
|
|
|
parser.add_option("-i", "--input", dest="ipath", help=_("parse input hand history"))
|
|
|
|
parser.add_option("-o", "--output", dest="opath", help=_("output translation to"), default="-")
|
|
|
|
parser.add_option("-f", "--follow", dest="follow", help=_("follow (tail -f) the input"), action="store_true", default=False)
|
2009-08-06 15:14:52 +02:00
|
|
|
parser.add_option("-q", "--quiet",
|
|
|
|
action="store_const", const=logging.CRITICAL, dest="verbosity", default=logging.INFO)
|
|
|
|
parser.add_option("-v", "--verbose",
|
|
|
|
action="store_const", const=logging.INFO, dest="verbosity")
|
|
|
|
parser.add_option("--vv",
|
|
|
|
action="store_const", const=logging.DEBUG, dest="verbosity")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
e = PartyPoker(in_path = options.ipath, out_path = options.opath, follow = options.follow)
|