2009-07-15 01:15:04 +02:00
#!/usr/bin/env python
2009-03-10 00:03:17 +01:00
# -*- coding: utf-8 -*-
#
2009-03-06 02:24:38 +01:00
# Copyright 2008, Carl Gherardi
#
# 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.
#
# 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.
#
# 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
########################################################################
2009-07-13 06:37:51 +02:00
# TODO: straighten out discards for draw games
2009-03-06 02:24:38 +01:00
import sys
from HandHistoryConverter import *
# PokerStars HH Format
class PokerStars ( HandHistoryConverter ) :
2009-03-15 06:32:52 +01:00
2009-07-13 06:37:51 +02:00
############################################################
# Class Variables
2009-03-06 02:24:38 +01:00
# Static regexes
2009-07-07 19:48:43 +02:00
re_GameInfo = re . compile ( """ PokerStars \ sGame \ s \ #(?P<HID>[0-9]+): \ s+
( Tournament \s \#(?P<TOURNO>\d+),\s(?P<BUYIN>[\$\+\d\.]+)\s)?
( ? P < MIXED > HORSE | 8 \- Game | HOSE ) ? \s ? \( ?
2009-07-14 16:55:39 +02:00
( ? P < GAME > Hold \' em|Razz|7 \ sCard \ sStud|7 \ sCard \ sStud \ sHi/Lo|Omaha|Omaha \ sHi/Lo|Badugi|Triple \ sDraw \ s2 \ -7 \ sLowball) \ s
( ? P < LIMIT > No \sLimit | Limit | Pot \sLimit ) \) ? , ? \s
2009-07-07 19:48:43 +02:00
( - \sLevel \s ( ? P < LEVEL > [ IVXLC ] + ) \s ) ? \( ?
( ? P < CURRENCY > \$ | ) ?
( ? P < SB > [ .0 - 9 ] + ) / \$ ?
( ? P < BB > [ .0 - 9 ] + ) \) \s - \s
( ? P < DATETIME > . * $ ) """ ,
re . MULTILINE | re . VERBOSE )
2009-03-31 08:44:19 +02:00
re_SplitHands = re . compile ( ' \n \n + ' )
re_TailSplitHands = re . compile ( ' ( \n \n \n +) ' )
2009-07-11 19:44:32 +02:00
re_HandInfo = re . compile ( """ ^Table \ s \' (?P<TABLE>[- \ a-zA-Z \ d]+) \' \ s
( ( ? P < MAX > \d + ) - max \s ) ?
( ? P < PLAY > \( Play \sMoney \) \s ) ?
( Seat \s \#(?P<BUTTON>\d+)\sis\sthe\sbutton)?""",
re . MULTILINE | re . VERBOSE )
2009-03-06 02:24:38 +01:00
re_Button = re . compile ( ' Seat #(?P<BUTTON> \ d+) is the button ' , re . MULTILINE )
re_PlayerInfo = re . compile ( ' ^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \ ( \ $?(?P<CASH>[.0-9]+) in chips \ ) ' , re . MULTILINE )
re_Board = re . compile ( r " \ [(?P<CARDS>.+) \ ] " )
# self.re_setHandInfoRegex('.*#(?P<HID>[0-9]+): Table (?P<TABLE>[ a-zA-Z]+) - \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) - (?P<GAMETYPE>.*) - (?P<HR>[0-9]+):(?P<MIN>[0-9]+) ET - (?P<YEAR>[0-9]+)/(?P<MON>[0-9]+)/(?P<DAY>[0-9]+)Table (?P<TABLE>[ a-zA-Z]+)\nSeat (?P<BUTTON>[0-9]+)')
2009-07-13 22:21:20 +02:00
mixes = { ' HORSE ' : ' horse ' , ' 8-Game ' : ' 8game ' , ' HOSE ' : ' hose ' }
2009-07-17 11:45:22 +02:00
def __init__ ( self , in_path = ' - ' , out_path = ' - ' , follow = False , autostart = True , index = 0 ) :
2009-03-06 02:24:38 +01:00
""" \
in_path ( default ' - ' = sys . stdin )
out_path ( default ' - ' = sys . stdout )
follow : whether to tail - f the input """
2009-07-17 11:45:22 +02:00
HandHistoryConverter . __init__ ( self , in_path , out_path , sitename = " PokerStars " , follow = follow , index = index )
2009-03-06 02:24:38 +01:00
logging . info ( " Initialising PokerStars converter class " )
self . filetype = " text "
self . codepage = " cp1252 "
2009-06-01 11:14:31 +02:00
self . siteId = 2 # Needs to match id entry in Sites database
2009-03-06 19:10:04 +01:00
if autostart :
self . start ( )
2009-03-06 02:24:38 +01:00
2009-03-14 15:01:40 +01:00
2009-03-10 00:03:17 +01:00
def compilePlayerRegexs ( self , hand ) :
2009-03-10 17:17:54 +01:00
players = set ( [ player [ 1 ] for player in hand . players ] )
2009-03-06 02:24:38 +01:00
if not players < = self . compiledPlayers : # x <= y means 'x is subset of y'
# we need to recompile the player regexs.
2009-07-13 06:37:51 +02:00
# TODO: should probably rename re_HeroCards and corresponding method,
# since they are used to find all cards on lines starting with "Dealt to:"
# They still identify the hero.
2009-03-06 02:24:38 +01:00
self . compiledPlayers = players
player_re = " (?P<PNAME> " + " | " . join ( map ( re . escape , players ) ) + " ) "
logging . debug ( " player_re: " + player_re )
self . re_PostSB = re . compile ( r " ^ %s : posts small blind \ $?(?P<SB>[.0-9]+) " % player_re , re . MULTILINE )
self . re_PostBB = re . compile ( r " ^ %s : posts big blind \ $?(?P<BB>[.0-9]+) " % player_re , re . MULTILINE )
self . re_Antes = re . compile ( r " ^ %s : posts the ante \ $?(?P<ANTE>[.0-9]+) " % player_re , re . MULTILINE )
2009-03-11 19:40:17 +01:00
self . re_BringIn = re . compile ( r " ^ %s : brings[- ]in( low|) for \ $?(?P<BRINGIN>[.0-9]+) " % player_re , re . MULTILINE )
2009-03-06 02:24:38 +01:00
self . re_PostBoth = re . compile ( r " ^ %s : posts small \ & big blinds \ [ \ $? (?P<SBBB>[.0-9]+) " % player_re , re . MULTILINE )
self . re_HeroCards = re . compile ( r " ^Dealt to %s (?: \ [(?P<OLDCARDS>.+?) \ ])?( \ [(?P<NEWCARDS>.+?) \ ]) " % player_re , re . MULTILINE )
2009-07-11 19:44:32 +02:00
self . re_Action = re . compile ( r """ ^ %s :(?P<ATYPE> \ sbets| \ schecks| \ sraises| \ scalls| \ sfolds| \ sdiscards| \ sstands \ spat)
( \s \$ ? ( ? P < BET > [ . \d ] + ) ) ? ( \sto \s \$ ? ( ? P < BETTO > [ . \d ] + ) ) ? # the number discarded goes in <BET>
( \scards ? ( \s \[ ( ? P < DISCARDED > . + ? ) \] ) ? ) ? """
% player_re , re . MULTILINE | re . VERBOSE )
2009-03-06 02:24:38 +01:00
self . re_ShowdownAction = re . compile ( r " ^ %s : shows \ [(?P<CARDS>.*) \ ] " % player_re , re . MULTILINE )
2009-07-13 06:37:51 +02:00
self . re_CollectPot = re . compile ( r " Seat (?P<SEAT>[0-9]+): %s ( \ (button \ ) | \ (small blind \ ) | \ (big blind \ ) )?(collected|showed \ [.* \ ] and won) \ ( \ $?(?P<POT>[. \ d]+) \ )(, mucked| with.*|) " % player_re , re . MULTILINE )
2009-03-06 02:24:38 +01:00
self . re_sitsOut = re . compile ( " ^ %s sits out " % player_re , re . MULTILINE )
2009-07-04 02:41:08 +02:00
self . re_ShownCards = re . compile ( " ^Seat (?P<SEAT>[0-9]+): %s ( \ (.* \ ) )?(?P<SHOWED>showed|mucked) \ [(?P<CARDS>.*) \ ].* " % player_re , re . MULTILINE )
2009-03-06 02:24:38 +01:00
def readSupportedGames ( self ) :
2009-03-14 11:48:34 +01:00
return [ [ " ring " , " hold " , " nl " ] ,
[ " ring " , " hold " , " pl " ] ,
[ " ring " , " hold " , " fl " ] ,
2009-07-07 19:48:43 +02:00
2009-03-14 11:48:34 +01:00
[ " ring " , " stud " , " fl " ] ,
2009-07-11 19:44:32 +02:00
[ " ring " , " draw " , " fl " ] ,
2009-07-07 19:48:43 +02:00
[ " tour " , " hold " , " nl " ] ,
[ " tour " , " hold " , " pl " ] ,
[ " tour " , " hold " , " fl " ] ,
[ " tour " , " stud " , " fl " ] ,
2009-03-14 11:48:34 +01:00
]
2009-03-06 02:24:38 +01:00
def determineGameType ( self , handText ) :
2009-07-11 19:44:32 +02:00
# inspect the handText and return the gametype dict
# gametype dict is:
# {'limitType': xxx, 'base': xxx, 'category': xxx}
2009-03-06 02:24:38 +01:00
2009-07-07 19:48:43 +02:00
info = { }
2009-03-06 02:24:38 +01:00
m = self . re_GameInfo . search ( handText )
2009-03-15 06:32:52 +01:00
if not m :
2009-03-06 02:24:38 +01:00
return None
2009-03-10 00:03:17 +01:00
mg = m . groupdict ( )
2009-07-11 19:44:32 +02:00
# translations from captured groups to fpdb info strings
2009-03-10 00:03:17 +01:00
limits = { ' No Limit ' : ' nl ' , ' Pot Limit ' : ' pl ' , ' Limit ' : ' fl ' }
2009-07-11 19:44:32 +02:00
games = { # base, category
" Hold ' em " : ( ' hold ' , ' holdem ' ) ,
' Omaha ' : ( ' hold ' , ' omahahi ' ) ,
' Omaha Hi/Lo ' : ( ' hold ' , ' omahahilo ' ) ,
' Razz ' : ( ' stud ' , ' razz ' ) ,
' 7 Card Stud ' : ( ' stud ' , ' studhi ' ) ,
' 7 Card Stud Hi/Lo ' : ( ' stud ' , ' studhilo ' ) ,
' Badugi ' : ( ' draw ' , ' badugi ' ) ,
' Triple Draw 2-7 Lowball ' : ( ' draw ' , ' 27_3draw ' ) ,
2009-03-10 00:03:17 +01:00
}
currencies = { u ' € ' : ' EUR ' , ' $ ' : ' USD ' , ' ' : ' T$ ' }
2009-07-07 19:48:43 +02:00
# I don't think this is doing what we think. mg will always have all
# the expected keys, but the ones that didn't match in the regex will
# have a value of None. It is OK if it throws an exception when it
# runs across an unknown game or limit or whatever.
2009-03-10 00:03:17 +01:00
if ' LIMIT ' in mg :
info [ ' limitType ' ] = limits [ mg [ ' LIMIT ' ] ]
if ' GAME ' in mg :
( info [ ' base ' ] , info [ ' category ' ] ) = games [ mg [ ' GAME ' ] ]
if ' SB ' in mg :
info [ ' sb ' ] = mg [ ' SB ' ]
if ' BB ' in mg :
info [ ' bb ' ] = mg [ ' BB ' ]
if ' CURRENCY ' in mg :
info [ ' currency ' ] = currencies [ mg [ ' CURRENCY ' ] ]
2009-07-11 19:44:32 +02:00
if ' TOURNO ' in mg and mg [ ' TOURNO ' ] == None :
2009-07-07 19:48:43 +02:00
info [ ' type ' ] = ' ring '
else :
info [ ' type ' ] = ' tour '
2009-07-11 19:44:32 +02:00
2009-03-10 00:03:17 +01:00
# NB: SB, BB must be interpreted as blinds or bets depending on limit type.
return info
2009-03-06 02:24:38 +01:00
def readHandInfo ( self , hand ) :
info = { }
m = self . re_HandInfo . search ( hand . handText , re . DOTALL )
2009-03-14 16:30:38 +01:00
if m :
info . update ( m . groupdict ( ) )
2009-07-11 19:44:32 +02:00
# hand.maxseats = int(m2.group(1))
else :
pass # throw an exception here, eh?
2009-03-06 02:24:38 +01:00
m = self . re_GameInfo . search ( hand . handText )
if m : info . update ( m . groupdict ( ) )
2009-07-11 19:44:32 +02:00
# m = self.re_Button.search(hand.handText)
# if m: info.update(m.groupdict())
2009-03-06 02:24:38 +01:00
# TODO : I rather like the idea of just having this dict as hand.info
logging . debug ( " readHandInfo: %s " % info )
for key in info :
if key == ' DATETIME ' :
2009-03-25 10:35:19 +01:00
#2008/11/12 10:00:48 CET [2008/11/12 4:00:48 ET]
#2008/08/17 - 01:14:43 (ET)
#2008/09/07 06:23:14 ET
m2 = re . search ( " (?P<Y>[0-9] {4} ) \ /(?P<M>[0-9] {2} ) \ /(?P<D>[0-9] {2} )[ \ - ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+) " , info [ key ] )
2009-06-07 23:39:19 +02:00
datetimestr = " %s / %s / %s %s : %s : %s " % ( m2 . group ( ' Y ' ) , m2 . group ( ' M ' ) , m2 . group ( ' D ' ) , m2 . group ( ' H ' ) , m2 . group ( ' MIN ' ) , m2 . group ( ' S ' ) )
hand . starttime = datetime . datetime . strptime ( datetimestr , " % Y/ % m/ %d % H: % M: % S " )
2009-03-06 02:24:38 +01:00
if key == ' HID ' :
hand . handid = info [ key ]
if key == ' TABLE ' :
hand . tablename = info [ key ]
if key == ' BUTTON ' :
hand . buttonpos = info [ key ]
2009-07-11 19:44:32 +02:00
if key == ' MAX ' :
2009-07-12 19:14:50 +02:00
hand . maxseats = int ( info [ key ] )
2009-07-11 19:44:32 +02:00
if key == ' MIXED ' :
2009-07-13 22:21:20 +02:00
if info [ key ] == None : hand . mixed = None
else : hand . mixed = self . mixes [ info [ key ] ]
2009-07-11 19:44:32 +02:00
if key == ' TOURNO ' :
hand . tourNo = info [ key ]
if key == ' BUYIN ' :
hand . buyin = info [ key ]
if key == ' LEVEL ' :
hand . level = info [ key ]
if key == ' PLAY ' and info [ ' PLAY ' ] != None :
2009-07-13 22:21:20 +02:00
# hand.currency = 'play' # overrides previously set value
hand . gametype [ ' currency ' ] = ' play '
2009-07-11 19:44:32 +02:00
2009-03-06 02:24:38 +01:00
def readButton ( self , hand ) :
m = self . re_Button . search ( hand . handText )
if m :
hand . buttonpos = int ( m . group ( ' BUTTON ' ) )
else :
logging . info ( ' readButton: not found ' )
def readPlayerStacks ( self , hand ) :
logging . debug ( " readPlayerStacks " )
m = self . re_PlayerInfo . finditer ( hand . handText )
players = [ ]
for a in m :
hand . addPlayer ( int ( a . group ( ' SEAT ' ) ) , a . group ( ' PNAME ' ) , a . group ( ' CASH ' ) )
def markStreets ( self , hand ) :
# PREFLOP = ** Dealing down cards **
# This re fails if, say, river is missing; then we don't get the ** that starts the river.
2009-03-11 15:42:49 +01:00
if hand . gametype [ ' base ' ] in ( " hold " ) :
2009-03-06 02:24:38 +01:00
m = re . search ( r " \ * \ * \ * HOLE CARDS \ * \ * \ *(?P<PREFLOP>.+(?= \ * \ * \ * FLOP \ * \ * \ *)|.+) "
r " ( \ * \ * \ * FLOP \ * \ * \ *(?P<FLOP> \ [ \ S \ S \ S \ S \ S \ S \ ].+(?= \ * \ * \ * TURN \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * TURN \ * \ * \ * \ [ \ S \ S \ S \ S \ S \ S] (?P<TURN> \ [ \ S \ S \ ].+(?= \ * \ * \ * RIVER \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * RIVER \ * \ * \ * \ [ \ S \ S \ S \ S \ S \ S \ S \ S] (?P<RIVER> \ [ \ S \ S \ ].+))? " , hand . handText , re . DOTALL )
2009-03-11 15:42:49 +01:00
elif hand . gametype [ ' base ' ] in ( " stud " ) :
2009-03-06 02:24:38 +01:00
m = re . search ( r " (?P<ANTES>.+(?= \ * \ * \ * 3rd STREET \ * \ * \ *)|.+) "
r " ( \ * \ * \ * 3rd STREET \ * \ * \ *(?P<THIRD>.+(?= \ * \ * \ * 4th STREET \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * 4th STREET \ * \ * \ *(?P<FOURTH>.+(?= \ * \ * \ * 5th STREET \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * 5th STREET \ * \ * \ *(?P<FIFTH>.+(?= \ * \ * \ * 6th STREET \ * \ * \ *)|.+))? "
2009-03-11 19:40:17 +01:00
r " ( \ * \ * \ * 6th STREET \ * \ * \ *(?P<SIXTH>.+(?= \ * \ * \ * RIVER \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * RIVER \ * \ * \ *(?P<SEVENTH>.+))? " , hand . handText , re . DOTALL )
2009-03-14 11:48:34 +01:00
elif hand . gametype [ ' base ' ] in ( " draw " ) :
m = re . search ( r " (?P<PREDEAL>.+(?= \ * \ * \ * DEALING HANDS \ * \ * \ *)|.+) "
r " ( \ * \ * \ * DEALING HANDS \ * \ * \ *(?P<DEAL>.+(?= \ * \ * \ * FIRST DRAW \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * FIRST DRAW \ * \ * \ *(?P<DRAWONE>.+(?= \ * \ * \ * SECOND DRAW \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * SECOND DRAW \ * \ * \ *(?P<DRAWTWO>.+(?= \ * \ * \ * THIRD DRAW \ * \ * \ *)|.+))? "
r " ( \ * \ * \ * THIRD DRAW \ * \ * \ *(?P<DRAWTHREE>.+))? " , hand . handText , re . DOTALL )
2009-03-06 02:24:38 +01:00
hand . addStreets ( m )
def readCommunityCards ( self , hand , street ) : # street has been matched by markStreets, so exists in this hand
if street in ( ' FLOP ' , ' TURN ' , ' RIVER ' ) : # a list of streets which get dealt community cards (i.e. all but PREFLOP)
#print "DEBUG readCommunityCards:", street, hand.streets.group(street)
m = self . re_Board . search ( hand . streets [ street ] )
hand . setCommunityCards ( street , m . group ( ' CARDS ' ) . split ( ' ' ) )
def readAntes ( self , hand ) :
logging . debug ( " reading antes " )
m = self . re_Antes . finditer ( hand . handText )
for player in m :
2009-03-11 19:40:17 +01:00
#~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
2009-03-06 02:24:38 +01:00
hand . addAnte ( player . group ( ' PNAME ' ) , player . group ( ' ANTE ' ) )
def readBringIn ( self , hand ) :
m = self . re_BringIn . search ( hand . handText , re . DOTALL )
if m :
2009-03-11 19:40:17 +01:00
#~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
2009-03-06 02:24:38 +01:00
hand . addBringIn ( m . group ( ' PNAME ' ) , m . group ( ' BRINGIN ' ) )
def readBlinds ( self , hand ) :
try :
m = self . re_PostSB . search ( hand . handText )
hand . addBlind ( m . group ( ' PNAME ' ) , ' small blind ' , m . group ( ' SB ' ) )
except : # no small blind
hand . addBlind ( None , None , None )
for a in self . re_PostBB . finditer ( hand . handText ) :
hand . addBlind ( a . group ( ' PNAME ' ) , ' big blind ' , a . group ( ' BB ' ) )
for a in self . re_PostBoth . finditer ( hand . handText ) :
2009-06-19 08:21:35 +02:00
hand . addBlind ( a . group ( ' PNAME ' ) , ' both ' , a . group ( ' SBBB ' ) )
2009-03-06 02:24:38 +01:00
2009-07-12 22:01:02 +02:00
# 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)
2009-03-06 02:24:38 +01:00
def readHeroCards ( self , hand ) :
2009-07-13 06:37:51 +02:00
# streets PREFLOP, PREDRAW, and THIRD are special cases beacause
# we need to grab hero's cards
for street in ( ' PREFLOP ' , ' DEAL ' ) :
2009-07-12 22:01:02 +02:00
if street in hand . streets . keys ( ) :
2009-07-13 06:37:51 +02:00
m = self . re_HeroCards . finditer ( hand . streets [ street ] )
for found in m :
# if m == None:
# hand.involved = False
# else:
hand . hero = found . group ( ' PNAME ' )
newcards = found . group ( ' NEWCARDS ' ) . split ( ' ' )
2009-07-12 22:01:02 +02:00
hand . addHoleCards ( street , hand . hero , closed = newcards , shown = False , mucked = False , dealt = True )
2009-07-13 06:37:51 +02:00
for street , text in hand . streets . iteritems ( ) :
2009-07-15 01:26:53 +02:00
if not text or street in ( ' PREFLOP ' , ' DEAL ' ) : continue # already done these
2009-07-13 06:37:51 +02:00
m = self . re_HeroCards . finditer ( hand . streets [ street ] )
for found in m :
player = found . group ( ' PNAME ' )
if found . group ( ' NEWCARDS ' ) == None :
newcards = [ ]
2009-03-14 11:48:34 +01:00
else :
2009-07-13 06:37:51 +02:00
newcards = found . group ( ' NEWCARDS ' ) . split ( ' ' )
if found . group ( ' OLDCARDS ' ) == None :
oldcards = [ ]
2009-03-14 11:48:34 +01:00
else :
2009-07-13 06:37:51 +02:00
oldcards = found . group ( ' OLDCARDS ' ) . split ( ' ' )
2009-03-14 11:48:34 +01:00
2009-07-13 06:37:51 +02:00
if street == ' THIRD ' and len ( newcards ) == 3 : # hero in stud game
hand . hero = player
hand . dealt . add ( player ) # need this for stud??
hand . addHoleCards ( street , player , closed = newcards [ 0 : 2 ] , open = [ newcards [ 2 ] ] , shown = False , mucked = False , dealt = False )
2009-03-14 11:48:34 +01:00
else :
2009-07-13 06:37:51 +02:00
hand . addHoleCards ( street , player , open = newcards , closed = oldcards , shown = False , mucked = False , dealt = False )
2009-03-14 11:48:34 +01:00
2009-07-13 06:37:51 +02:00
# 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)
2009-03-14 11:48:34 +01:00
2009-07-13 06:37:51 +02:00
# 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)
2009-03-06 02:24:38 +01:00
def readAction ( self , hand , street ) :
m = self . re_Action . finditer ( hand . streets [ street ] )
for action in m :
2009-07-11 19:44:32 +02:00
acts = action . groupdict ( )
2009-03-06 02:24:38 +01:00
if action . group ( ' ATYPE ' ) == ' raises ' :
hand . addRaiseBy ( street , action . group ( ' PNAME ' ) , action . group ( ' BET ' ) )
elif action . group ( ' ATYPE ' ) == ' calls ' :
hand . addCall ( street , action . group ( ' PNAME ' ) , action . group ( ' BET ' ) )
elif action . group ( ' ATYPE ' ) == ' bets ' :
hand . addBet ( street , action . group ( ' PNAME ' ) , action . group ( ' BET ' ) )
elif action . group ( ' ATYPE ' ) == ' folds ' :
hand . addFold ( street , action . group ( ' PNAME ' ) )
elif action . group ( ' ATYPE ' ) == ' checks ' :
hand . addCheck ( street , action . group ( ' PNAME ' ) )
2009-03-14 11:48:34 +01:00
elif action . group ( ' ATYPE ' ) == ' discards ' :
2009-07-11 19:44:32 +02:00
hand . addDiscard ( street , action . group ( ' PNAME ' ) , action . group ( ' BET ' ) , action . group ( ' DISCARDED ' ) )
2009-03-14 11:48:34 +01:00
elif action . group ( ' ATYPE ' ) == ' stands pat ' :
hand . addStandsPat ( street , action . group ( ' PNAME ' ) )
2009-03-06 02:24:38 +01:00
else :
2009-03-14 11:48:34 +01:00
print " DEBUG: unimplemented readAction: ' %s ' ' %s ' " % ( action . group ( ' PNAME ' ) , action . group ( ' ATYPE ' ) , )
2009-03-06 02:24:38 +01:00
def readShowdownActions ( self , hand ) :
2009-07-12 22:01:02 +02:00
# TODO: pick up mucks also
2009-03-06 02:24:38 +01:00
for shows in self . re_ShowdownAction . finditer ( hand . handText ) :
2009-07-12 22:01:02 +02:00
cards = shows . group ( ' CARDS ' ) . split ( ' ' )
2009-03-06 02:24:38 +01:00
hand . addShownCards ( cards , shows . group ( ' PNAME ' ) )
def readCollectPot ( self , hand ) :
for m in self . re_CollectPot . finditer ( hand . handText ) :
hand . addCollectPot ( player = m . group ( ' PNAME ' ) , pot = m . group ( ' POT ' ) )
def readShownCards ( self , hand ) :
for m in self . re_ShownCards . finditer ( hand . handText ) :
if m . group ( ' CARDS ' ) is not None :
cards = m . group ( ' CARDS ' )
2009-07-04 20:35:20 +02:00
cards = cards . split ( ' ' ) # needs to be a list, not a set--stud needs the order
2009-07-04 00:59:50 +02:00
( shown , mucked ) = ( False , False )
if m . group ( ' SHOWED ' ) == " showed " : shown = True
elif m . group ( ' SHOWED ' ) == " mucked " : mucked = True
hand . addShownCards ( cards = cards , player = m . group ( ' PNAME ' ) , shown = shown , mucked = mucked )
2009-03-06 02:24:38 +01:00
if __name__ == " __main__ " :
parser = OptionParser ( )
2009-07-15 01:15:04 +02:00
parser . add_option ( " -i " , " --input " , dest = " ipath " , help = " parse input hand history " , default = " regression-test-files/stars/horse/HH20090226 Natalie V - $0.10-$0.20 - HORSE.txt " )
2009-03-06 02:24:38 +01:00
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 )
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 ( )
LOG_FILENAME = ' ./logging.out '
logging . basicConfig ( filename = LOG_FILENAME , level = options . verbosity )
e = PokerStars ( in_path = options . ipath , out_path = options . opath , follow = options . follow )