Add 'Currencies' filter to the ring player stats viewer.
[fpdb-dooglus.git] / pyfpdb / PokerStarsToFpdb.py
blob5e9f00bbdcee4d322e448fa25cdaa089391bb54d
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright 2008-2011, Carl Gherardi
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ########################################################################
21 import L10n
22 _ = L10n.get_translation()
24 # TODO: straighten out discards for draw games
26 import sys
27 from HandHistoryConverter import *
28 from decimal_wrapper import Decimal
30 # PokerStars HH Format
32 class PokerStars(HandHistoryConverter):
34 # Class Variables
36 sitename = "PokerStars"
37 filetype = "text"
38 codepage = ("utf8", "cp1252")
39 siteId = 2 # Needs to match id entry in Sites database
40 sym = {'USD': "\$", 'CAD': "\$", 'T$': "", "EUR": "\xe2\x82\xac", "GBP": "\xa3", "play": ""} # ADD Euro, Sterling, etc HERE
41 substitutions = {
42 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
43 'LS' : u"\$|\xe2\x82\xac|\u20ac|", # legal currency symbols - Euro(cp1252, utf-8)
44 'PLYR': r'(?P<PNAME>.+?)',
45 'CUR': u"(\$|\xe2\x82\xac|\u20ac|)",
48 # translations from captured groups to fpdb info strings
49 Lim_Blinds = { '0.04': ('0.01', '0.02'), '0.08': ('0.02', '0.04'),
50 '0.10': ('0.02', '0.05'), '0.20': ('0.05', '0.10'),
51 '0.40': ('0.10', '0.20'), '0.50': ('0.10', '0.25'),
52 '1.00': ('0.25', '0.50'), '1': ('0.25', '0.50'),
53 '2.00': ('0.50', '1.00'), '2': ('0.50', '1.00'),
54 '4.00': ('1.00', '2.00'), '4': ('1.00', '2.00'),
55 '6.00': ('1.00', '3.00'), '6': ('1.00', '3.00'),
56 '8.00': ('2.00', '4.00'), '8': ('2.00', '4.00'),
57 '10.00': ('2.00', '5.00'), '10': ('2.00', '5.00'),
58 '20.00': ('5.00', '10.00'), '20': ('5.00', '10.00'),
59 '30.00': ('10.00', '15.00'), '30': ('10.00', '15.00'),
60 '40.00': ('10.00', '20.00'), '40': ('10.00', '20.00'),
61 '60.00': ('15.00', '30.00'), '60': ('15.00', '30.00'),
62 '80.00': ('20.00', '40.00'), '80': ('20.00', '40.00'),
63 '100.00': ('25.00', '50.00'), '100': ('25.00', '50.00'),
64 '200.00': ('50.00', '100.00'), '200': ('50.00', '100.00'),
65 '400.00': ('100.00', '200.00'), '400': ('100.00', '200.00'),
66 '800.00': ('200.00', '400.00'), '800': ('200.00', '400.00'),
67 '1000.00': ('250.00', '500.00'),'1000': ('250.00', '500.00')
70 limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
71 games = { # base, category
72 "Hold'em" : ('hold','holdem'),
73 'Omaha' : ('hold','omahahi'),
74 'Omaha Hi/Lo' : ('hold','omahahilo'),
75 'Razz' : ('stud','razz'),
76 'RAZZ' : ('stud','razz'),
77 '7 Card Stud' : ('stud','studhi'),
78 '7 Card Stud Hi/Lo' : ('stud','studhilo'),
79 'Badugi' : ('draw','badugi'),
80 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
81 'Single Draw 2-7 Lowball' : ('draw','27_1draw'),
82 '5 Card Draw' : ('draw','fivedraw')
84 mixes = {
85 'HORSE': 'horse',
86 '8-Game': '8game',
87 'HOSE': 'hose',
88 'Mixed PLH/PLO': 'plh_plo',
89 'Mixed Omaha H/L': 'plo_lo',
90 'Mixed Hold\'em': 'mholdem',
91 'Triple Stud': '3stud'
92 } # Legal mixed games
93 currencies = { u'€':'EUR', '$':'USD', '':'T$' }
95 # Static regexes
96 re_GameInfo = re.compile(u"""
97 PokerStars(\sHome)?\sGame\s\#(?P<HID>[0-9]+):\s+
98 (\{.*\}\s+)?(Tournament\s\# # open paren of tournament info
99 (?P<TOURNO>\d+),\s
100 # here's how I plan to use LS
101 (?P<BUYIN>(?P<BIAMT>[%(LS)s\d\.]+)?\+?(?P<BIRAKE>[%(LS)s\d\.]+)?\+?(?P<BOUNTY>[%(LS)s\d\.]+)?\s?(?P<TOUR_ISO>%(LEGAL_ISO)s)?|Freeroll)\s+)?
102 # close paren of tournament info
103 (?P<MIXED>HORSE|8\-Game|HOSE|Mixed\sOmaha\sH/L|Mixed\sHold\'em|Mixed\sPLH/PLO|Triple\sStud)?\s?\(?
104 (?P<GAME>Hold\'em|Razz|RAZZ|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball|Single\sDraw\s2\-7\sLowball|5\sCard\sDraw)\s
105 (?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\)?,?\s
106 (-\s)?
107 (Match.*)? #TODO: waiting for reply from user as to what this means
108 (Level\s(?P<LEVEL>[IVXLC]+)\s)?
109 \(? # open paren of the stakes
110 (?P<CURRENCY>%(LS)s|)?
111 (?P<SB>[.0-9]+)/(%(LS)s)?
112 (?P<BB>[.0-9]+)
113 (?P<BLAH>\s-\s[%(LS)s\d\.]+\sCap\s-\s)? # Optional Cap part
114 \s?(?P<ISO>%(LEGAL_ISO)s)?
115 \) # close paren of the stakes
116 (?P<BLAH2>\s\[AAMS\sID:\s[A-Z0-9]+\])? # AAMS ID: in .it HH's
117 \s-\s
118 (?P<DATETIME>.*$)
119 """ % substitutions, re.MULTILINE|re.VERBOSE)
121 re_PlayerInfo = re.compile(u"""
122 ^Seat\s(?P<SEAT>[0-9]+):\s
123 (?P<PNAME>.*)\s
124 \((%(LS)s)?(?P<CASH>[.0-9]+)\sin\schips\)""" % substitutions,
125 re.MULTILINE|re.VERBOSE)
127 re_HandInfo = re.compile("""
128 ^Table\s\'(?P<TABLE>[-\ \#a-zA-Z\d\']+)\'\s
129 ((?P<MAX>\d+)-max\s)?
130 (?P<PLAY>\(Play\sMoney\)\s)?
131 (Seat\s\#(?P<BUTTON>\d+)\sis\sthe\sbutton)?""",
132 re.MULTILINE|re.VERBOSE)
134 re_SplitHands = re.compile('\n\n+')
135 re_TailSplitHands = re.compile('(\n\n\n+)')
136 re_Button = re.compile('Seat #(?P<BUTTON>\d+) is the button', re.MULTILINE)
137 re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
138 # 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]+)')
140 re_DateTime = re.compile("""(?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]+)""", re.MULTILINE)
141 # revised re including timezone (not currently used):
142 #re_DateTime = re.compile("""(?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]+) \(?(?P<TZ>[A-Z0-9]+)""", re.MULTILINE)
144 # These used to be compiled per player, but regression tests say
145 # we don't have to, and it makes life faster.
146 re_PostSB = re.compile(r"^%(PLYR)s: posts small blind %(CUR)s(?P<SB>[.0-9]+)" % substitutions, re.MULTILINE)
147 re_PostBB = re.compile(r"^%(PLYR)s: posts big blind %(CUR)s(?P<BB>[.0-9]+)" % substitutions, re.MULTILINE)
148 re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P<ANTE>[.0-9]+)" % substitutions, re.MULTILINE)
149 re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P<BRINGIN>[.0-9]+)" % substitutions, re.MULTILINE)
150 re_PostBoth = re.compile(r"^%(PLYR)s: posts small \& big blinds %(CUR)s(?P<SBBB>[.0-9]+)" % substitutions, re.MULTILINE)
151 re_HeroCards = re.compile(r"^Dealt to %(PLYR)s(?: \[(?P<OLDCARDS>.+?)\])?( \[(?P<NEWCARDS>.+?)\])" % substitutions, re.MULTILINE)
152 re_Action = re.compile(r"""
153 ^%(PLYR)s:(?P<ATYPE>\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat)
154 (\s%(CUR)s(?P<BET>[.\d]+))?(\sto\s%(CUR)s(?P<BETTO>[.\d]+))? # the number discarded goes in <BET>
155 \s*(and\sis\sall.in)?
156 (and\shas\sreached\sthe\s[%(CUR)s\d\.]+\scap)?
157 (\son|\scards?)?
158 (\s\[(?P<CARDS>.+?)\])?\s*$"""
159 % substitutions, re.MULTILINE|re.VERBOSE)
160 re_ShowdownAction = re.compile(r"^%s: shows \[(?P<CARDS>.*)\]" % substitutions['PLYR'], re.MULTILINE)
161 re_sitsOut = re.compile("^%s sits out" % substitutions['PLYR'], re.MULTILINE)
162 re_ShownCards = re.compile("^Seat (?P<SEAT>[0-9]+): %s (\(.*\) )?(?P<SHOWED>showed|mucked) \[(?P<CARDS>.*)\]( and won \([.\d]+\) with (?P<STRING>.*))?" % substitutions['PLYR'], re.MULTILINE)
163 re_CollectPot = re.compile(r"Seat (?P<SEAT>[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P<POT>[.\d]+)\)(, mucked| with.*|)" % substitutions, re.MULTILINE)
164 re_WinningRankOne = re.compile(u"^%(PLYR)s wins the tournament and receives %(CUR)s(?P<AMT>[\.0-9]+) - congratulations!$" % substitutions, re.MULTILINE)
165 re_WinningRankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place and received %(CUR)s(?P<AMT>[.0-9]+)\.$" % substitutions, re.MULTILINE)
166 re_RankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place$" % substitutions, re.MULTILINE)
168 def compilePlayerRegexs(self, hand):
169 pass
171 def readSupportedGames(self):
172 return [["ring", "hold", "nl"],
173 ["ring", "hold", "pl"],
174 ["ring", "hold", "fl"],
176 ["ring", "stud", "fl"],
178 ["ring", "draw", "fl"],
179 ["ring", "draw", "pl"],
180 ["ring", "draw", "nl"],
182 ["tour", "hold", "nl"],
183 ["tour", "hold", "pl"],
184 ["tour", "hold", "fl"],
186 ["tour", "stud", "fl"],
188 ["tour", "draw", "fl"],
189 ["tour", "draw", "pl"],
190 ["tour", "draw", "nl"],
193 def determineGameType(self, handText):
194 info = {}
195 m = self.re_GameInfo.search(handText)
196 if not m:
197 tmp = handText[0:150]
198 log.error(_("Unable to recognise gametype from: '%s'") % tmp)
199 log.error("determineGameType: " + _("Raising FpdbParseError"))
200 raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp)
202 mg = m.groupdict()
203 if 'LIMIT' in mg:
204 info['limitType'] = self.limits[mg['LIMIT']]
205 if 'GAME' in mg:
206 (info['base'], info['category']) = self.games[mg['GAME']]
207 if 'SB' in mg:
208 info['sb'] = mg['SB']
209 if 'BB' in mg:
210 info['bb'] = mg['BB']
211 if 'CURRENCY' in mg:
212 info['currency'] = self.currencies[mg['CURRENCY']]
213 if 'MIXED' in mg:
214 if mg['MIXED'] is not None: info['mix'] = self.mixes[mg['MIXED']]
216 if 'TOURNO' in mg and mg['TOURNO'] is None:
217 info['type'] = 'ring'
218 else:
219 info['type'] = 'tour'
221 if info['limitType'] == 'fl' and info['bb'] is not None and info['type'] == 'ring':
222 try:
223 info['sb'] = self.Lim_Blinds[mg['BB']][0]
224 info['bb'] = self.Lim_Blinds[mg['BB']][1]
225 except KeyError:
226 log.error(_("Lim_Blinds has no lookup for '%s'") % mg['BB'])
227 log.error("determineGameType: " + _("Raising FpdbParseError"))
228 raise FpdbParseError(_("Lim_Blinds has no lookup for '%s'") % mg['BB'])
230 return info
232 def readHandInfo(self, hand):
233 info = {}
234 m = self.re_HandInfo.search(hand.handText,re.DOTALL)
235 m2 = self.re_GameInfo.search(hand.handText)
236 if m is None or m2 is None:
237 log.error(_("No match in readHandInfo: '%s'") % hand.handText[0:100])
238 raise FpdbParseError(_("No match in readHandInfo: '%s'") % hand.handText[0:100])
240 info.update(m.groupdict())
241 info.update(m2.groupdict())
243 log.debug("readHandInfo: %s" % info)
244 for key in info:
245 if key == 'DATETIME':
246 #2008/11/12 10:00:48 CET [2008/11/12 4:00:48 ET] # (both dates are parsed so ET date overrides the other)
247 #2008/08/17 - 01:14:43 (ET)
248 #2008/09/07 06:23:14 ET
249 m1 = self.re_DateTime.finditer(info[key])
250 datetimestr = "2000/01/01 00:00:00" # default used if time not found
251 for a in m1:
252 datetimestr = "%s/%s/%s %s:%s:%s" % (a.group('Y'), a.group('M'),a.group('D'),a.group('H'),a.group('MIN'),a.group('S'))
253 #tz = a.group('TZ') # just assume ET??
254 #print " tz = ", tz, " datetime =", datetimestr
255 hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
256 hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, "ET", "UTC")
257 if key == 'HID':
258 hand.handid = info[key]
259 if key == 'TOURNO':
260 hand.tourNo = info[key]
261 if key == 'BUYIN':
262 if hand.tourNo!=None:
263 #print "DEBUG: info['BUYIN']: %s" % info['BUYIN']
264 #print "DEBUG: info['BIAMT']: %s" % info['BIAMT']
265 #print "DEBUG: info['BIRAKE']: %s" % info['BIRAKE']
266 #print "DEBUG: info['BOUNTY']: %s" % info['BOUNTY']
267 if info[key] == 'Freeroll':
268 hand.buyin = 0
269 hand.fee = 0
270 hand.buyinCurrency = "FREE"
271 else:
272 if info[key].find("$")!=-1:
273 hand.buyinCurrency="USD"
274 elif info[key].find(u"€")!=-1:
275 hand.buyinCurrency="EUR"
276 elif info[key].find("FPP")!=-1:
277 hand.buyinCurrency="PSFP"
278 elif re.match("^[0-9+]*$", info[key]):
279 hand.buyinCurrency="play"
280 else:
281 #FIXME: handle other currencies, play money
282 raise FpdbParseError(_("Failed to detect currency.") + " " + _("Hand ID: %s: '%s'") % (hand.handid, info[key]))
284 info['BIAMT'] = info['BIAMT'].strip(u'$€FPP')
286 if hand.buyinCurrency!="PSFP":
287 if info['BOUNTY'] != None:
288 # There is a bounty, Which means we need to switch BOUNTY and BIRAKE values
289 tmp = info['BOUNTY']
290 info['BOUNTY'] = info['BIRAKE']
291 info['BIRAKE'] = tmp
292 info['BOUNTY'] = info['BOUNTY'].strip(u'$€') # Strip here where it isn't 'None'
293 hand.koBounty = int(100*Decimal(info['BOUNTY']))
294 hand.isKO = True
295 else:
296 hand.isKO = False
298 info['BIRAKE'] = info['BIRAKE'].strip(u'$€')
300 hand.buyin = int(100*Decimal(info['BIAMT']))
301 hand.fee = int(100*Decimal(info['BIRAKE']))
302 else:
303 hand.buyin = int(Decimal(info['BIAMT']))
304 hand.fee = 0
305 if key == 'LEVEL':
306 hand.level = info[key]
308 if key == 'TABLE':
309 if hand.tourNo != None:
310 hand.tablename = re.split(" ", info[key])[1]
311 else:
312 hand.tablename = info[key]
313 if key == 'BUTTON':
314 hand.buttonpos = info[key]
315 if key == 'MAX' and info[key] != None:
316 hand.maxseats = int(info[key])
318 if key == 'PLAY' and info['PLAY'] is not None:
319 # hand.currency = 'play' # overrides previously set value
320 hand.gametype['currency'] = 'play'
322 def readButton(self, hand):
323 m = self.re_Button.search(hand.handText)
324 if m:
325 hand.buttonpos = int(m.group('BUTTON'))
326 else:
327 log.info(_('readButton: not found'))
329 def readPlayerStacks(self, hand):
330 log.debug("readPlayerStacks")
331 m = self.re_PlayerInfo.finditer(hand.handText)
332 for a in m:
333 hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH'))
335 def markStreets(self, hand):
336 # PREFLOP = ** Dealing down cards **
337 # This re fails if, say, river is missing; then we don't get the ** that starts the river.
338 if hand.gametype['base'] in ("hold"):
339 m = re.search(r"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
340 r"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S \S\S \S\S\].+(?=\*\*\* TURN \*\*\*)|.+))?"
341 r"(\*\*\* TURN \*\*\* \[\S\S \S\S \S\S] (?P<TURN>\[\S\S\].+(?=\*\*\* RIVER \*\*\*)|.+))?"
342 r"(\*\*\* RIVER \*\*\* \[\S\S \S\S \S\S \S\S] (?P<RIVER>\[\S\S\].+))?", hand.handText,re.DOTALL)
343 elif hand.gametype['base'] in ("stud"):
344 m = re.search(r"(?P<ANTES>.+(?=\*\*\* 3rd STREET \*\*\*)|.+)"
345 r"(\*\*\* 3rd STREET \*\*\*(?P<THIRD>.+(?=\*\*\* 4th STREET \*\*\*)|.+))?"
346 r"(\*\*\* 4th STREET \*\*\*(?P<FOURTH>.+(?=\*\*\* 5th STREET \*\*\*)|.+))?"
347 r"(\*\*\* 5th STREET \*\*\*(?P<FIFTH>.+(?=\*\*\* 6th STREET \*\*\*)|.+))?"
348 r"(\*\*\* 6th STREET \*\*\*(?P<SIXTH>.+(?=\*\*\* RIVER \*\*\*)|.+))?"
349 r"(\*\*\* RIVER \*\*\*(?P<SEVENTH>.+))?", hand.handText,re.DOTALL)
350 elif hand.gametype['base'] in ("draw"):
351 if hand.gametype['category'] in ('27_1draw', 'fivedraw'):
352 # There is no marker between deal and draw in Stars single draw games
353 # This unfortunately affects the accounting.
354 m = re.search(r"(?P<PREDEAL>.+(?=\*\*\* DEALING HANDS \*\*\*)|.+)"
355 r"(\*\*\* DEALING HANDS \*\*\*(?P<DEAL>.+(?=(: stands pat on|: discards))|.+))?"
356 r"((: stands pat on|: discards)(?P<DRAWONE>.+))?", hand.handText,re.DOTALL)
357 else:
358 m = re.search(r"(?P<PREDEAL>.+(?=\*\*\* DEALING HANDS \*\*\*)|.+)"
359 r"(\*\*\* DEALING HANDS \*\*\*(?P<DEAL>.+(?=\*\*\* FIRST DRAW \*\*\*)|.+))?"
360 r"(\*\*\* FIRST DRAW \*\*\*(?P<DRAWONE>.+(?=\*\*\* SECOND DRAW \*\*\*)|.+))?"
361 r"(\*\*\* SECOND DRAW \*\*\*(?P<DRAWTWO>.+(?=\*\*\* THIRD DRAW \*\*\*)|.+))?"
362 r"(\*\*\* THIRD DRAW \*\*\*(?P<DRAWTHREE>.+))?", hand.handText,re.DOTALL)
363 hand.addStreets(m)
365 def readCommunityCards(self, hand, street): # street has been matched by markStreets, so exists in this hand
366 if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
367 #print "DEBUG readCommunityCards:", street, hand.streets.group(street)
368 m = self.re_Board.search(hand.streets[street])
369 hand.setCommunityCards(street, m.group('CARDS').split(' '))
371 def readAntes(self, hand):
372 log.debug(_("reading antes"))
373 m = self.re_Antes.finditer(hand.handText)
374 for player in m:
375 #~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
376 hand.addAnte(player.group('PNAME'), player.group('ANTE'))
378 def readBringIn(self, hand):
379 m = self.re_BringIn.search(hand.handText,re.DOTALL)
380 if m:
381 #~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
382 hand.addBringIn(m.group('PNAME'), m.group('BRINGIN'))
384 def readBlinds(self, hand):
385 liveBlind = True
386 for a in self.re_PostSB.finditer(hand.handText):
387 if liveBlind:
388 hand.addBlind(a.group('PNAME'), 'small blind', a.group('SB'))
389 liveBlind = False
390 else:
391 # Post dead blinds as ante
392 hand.addBlind(a.group('PNAME'), 'secondsb', a.group('SB'))
393 for a in self.re_PostBB.finditer(hand.handText):
394 hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
395 for a in self.re_PostBoth.finditer(hand.handText):
396 hand.addBlind(a.group('PNAME'), 'both', a.group('SBBB'))
398 def readHeroCards(self, hand):
399 # streets PREFLOP, PREDRAW, and THIRD are special cases beacause
400 # we need to grab hero's cards
401 for street in ('PREFLOP', 'DEAL'):
402 if street in hand.streets.keys():
403 m = self.re_HeroCards.finditer(hand.streets[street])
404 for found in m:
405 # if m == None:
406 # hand.involved = False
407 # else:
408 hand.hero = found.group('PNAME')
409 newcards = found.group('NEWCARDS').split(' ')
410 hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
412 for street, text in hand.streets.iteritems():
413 if not text or street in ('PREFLOP', 'DEAL'): continue # already done these
414 m = self.re_HeroCards.finditer(hand.streets[street])
415 for found in m:
416 player = found.group('PNAME')
417 if found.group('NEWCARDS') is None:
418 newcards = []
419 else:
420 newcards = found.group('NEWCARDS').split(' ')
421 if found.group('OLDCARDS') is None:
422 oldcards = []
423 else:
424 oldcards = found.group('OLDCARDS').split(' ')
426 if street == 'THIRD' and len(newcards) == 3: # hero in stud game
427 hand.hero = player
428 hand.dealt.add(player) # need this for stud??
429 hand.addHoleCards(street, player, closed=newcards[0:2], open=[newcards[2]], shown=False, mucked=False, dealt=False)
430 else:
431 hand.addHoleCards(street, player, open=newcards, closed=oldcards, shown=False, mucked=False, dealt=False)
434 def readAction(self, hand, street):
435 m = self.re_Action.finditer(hand.streets[street])
436 for action in m:
437 acts = action.groupdict()
438 #print "DEBUG: acts: %s" %acts
439 if action.group('ATYPE') == ' raises':
440 hand.addRaiseBy( street, action.group('PNAME'), action.group('BET') )
441 elif action.group('ATYPE') == ' calls':
442 hand.addCall( street, action.group('PNAME'), action.group('BET') )
443 elif action.group('ATYPE') == ' bets':
444 hand.addBet( street, action.group('PNAME'), action.group('BET') )
445 elif action.group('ATYPE') == ' folds':
446 hand.addFold( street, action.group('PNAME'))
447 elif action.group('ATYPE') == ' checks':
448 hand.addCheck( street, action.group('PNAME'))
449 elif action.group('ATYPE') == ' discards':
450 hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('CARDS'))
451 elif action.group('ATYPE') == ' stands pat':
452 hand.addStandsPat( street, action.group('PNAME'), action.group('CARDS'))
453 else:
454 print (_("DEBUG:") + " " + _("Unimplemented %s: '%s' '%s'") % ("readAction", action.group('PNAME'), action.group('ATYPE')))
457 def readShowdownActions(self, hand):
458 # TODO: pick up mucks also??
459 for shows in self.re_ShowdownAction.finditer(hand.handText):
460 cards = shows.group('CARDS').split(' ')
461 hand.addShownCards(cards, shows.group('PNAME'))
463 for winningrankone in self.re_WinningRankOne.finditer(hand.handText):
464 hand.addPlayerRank (winningrankone.group('PNAME'),int(100*Decimal(winningrankone.group('AMT'))),1)
466 for winningrankothers in self.re_WinningRankOther.finditer(hand.handText):
467 hand.addPlayerRank (winningrankothers.group('PNAME'),int(100*Decimal(winningrankothers.group('AMT'))),winningrankothers.group('RANK'))
469 for rankothers in self.re_RankOther.finditer(hand.handText):
470 hand.addPlayerRank (rankothers.group('PNAME'),0,rankothers.group('RANK'))
472 def readCollectPot(self,hand):
473 for m in self.re_CollectPot.finditer(hand.handText):
474 hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT'))
476 def readShownCards(self,hand):
477 for m in self.re_ShownCards.finditer(hand.handText):
478 if m.group('CARDS') is not None:
479 cards = m.group('CARDS')
480 cards = cards.split(' ') # needs to be a list, not a set--stud needs the order
481 string = m.group('STRING')
483 (shown, mucked) = (False, False)
484 if m.group('SHOWED') == "showed": shown = True
485 elif m.group('SHOWED') == "mucked": mucked = True
487 #print "DEBUG: hand.addShownCards(%s, %s, %s, %s)" %(cards, m.group('PNAME'), shown, mucked)
488 hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=shown, mucked=mucked, string=string)