Use debian 2.7 only
[fpbd-bostik.git] / pyfpdb / BetOnlineToFpdb.py
blobcfc0851e902dbdc1992f22e8471409731f7e581b
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright 2008-2011, Chaz Littlejohn
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 # BetOnline HH Format
32 class BetOnline(HandHistoryConverter):
34 # Class Variables
36 sitename = "BetOnline"
37 filetype = "text"
38 codepage = ("utf8", "cp1252")
39 siteId = 19 # 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 'LS' : u"\$|\xe2\x82\xac|\u20ac|", # legal currency symbols - Euro(cp1252, utf-8)
43 'PLYR': r'(?P<PNAME>.+?)'
46 # translations from captured groups to fpdb info strings
47 Lim_Blinds = { '0.04': ('0.01', '0.02'), '0.08': ('0.02', '0.04'),
48 '0.10': ('0.02', '0.05'), '0.20': ('0.05', '0.10'),
49 '0.40': ('0.10', '0.20'), '0.50': ('0.10', '0.25'),
50 '1.00': ('0.25', '0.50'), '1': ('0.25', '0.50'),
51 '2.00': ('0.50', '1.00'), '2': ('0.50', '1.00'),
52 '4.00': ('1.00', '2.00'), '4': ('1.00', '2.00'),
53 '6.00': ('1.00', '3.00'), '6': ('1.00', '3.00'),
54 '8.00': ('2.00', '4.00'), '8': ('2.00', '4.00'),
55 '10.00': ('2.00', '5.00'), '10': ('2.00', '5.00'),
56 '20.00': ('5.00', '10.00'), '20': ('5.00', '10.00'),
57 '30.00': ('10.00', '15.00'), '30': ('10.00', '15.00'),
58 '40.00': ('10.00', '20.00'), '40': ('10.00', '20.00'),
59 '60.00': ('15.00', '30.00'), '60': ('15.00', '30.00'),
60 '80.00': ('20.00', '40.00'), '80': ('20.00', '40.00'),
61 '100.00': ('25.00', '50.00'), '100': ('25.00', '50.00'),
62 '200.00': ('50.00', '100.00'), '200': ('50.00', '100.00'),
63 '400.00': ('100.00', '200.00'), '400': ('100.00', '200.00'),
64 '800.00': ('200.00', '400.00'), '800': ('200.00', '400.00'),
65 '1000.00': ('250.00', '500.00'),'1000': ('250.00', '500.00')
68 limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
69 games = { # base, category
70 "Hold'em" : ('hold','holdem'),
71 'Omaha' : ('hold','omahahi'),
72 'Omaha Hi/Lo' : ('hold','omahahilo'),
73 'Razz' : ('stud','razz'),
74 'RAZZ' : ('stud','razz'),
75 '7 Card Stud' : ('stud','studhi'),
76 '7 Card Stud Hi/Lo' : ('stud','studhilo'),
77 'Badugi' : ('draw','badugi'),
78 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
79 'Single Draw 2-7 Lowball' : ('draw','27_1draw'),
80 '5 Card Draw' : ('draw','fivedraw')
82 mixes = {
83 'HORSE': 'horse',
84 '8-Game': '8game',
85 'HOSE': 'hose',
86 'Mixed PLH/PLO': 'plh_plo',
87 'Mixed Omaha H/L': 'plo_lo',
88 'Mixed Hold\'em': 'mholdem',
89 'Triple Stud': '3stud'
90 } # Legal mixed games
91 currencies = { u'€':'EUR', '$':'USD', '':'T$' }
93 # Static regexes
94 re_GameInfo = re.compile(u"""
95 BetOnline\sPoker\sGame\s\#(?P<HID>[0-9]+):\s+
96 (\{.*\}\s+)?(Tournament\s\# # open paren of tournament info
97 (?P<TOURNO>\d+):\s?
98 # here's how I plan to use LS
99 (?P<BUYIN>(?P<BIAMT>[%(LS)s\d\.]+)?\+?(?P<BIRAKE>[%(LS)s\d\.]+)?\+?(?P<BOUNTY>[%(LS)s\d\.]+)?\s?|Freeroll|)\s+)?
100 # close paren of tournament info
101 (?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
102 (?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)?,?\s?
103 \(? # open paren of the stakes
104 (?P<CURRENCY>%(LS)s|)?
105 (?P<SB>[.0-9]+)/(%(LS)s)?
106 (?P<BB>[.0-9]+)
107 \)? # close paren of the stakes
108 \s-\s
109 (?P<DATETIME>.*$)
110 """ % substitutions, re.MULTILINE|re.VERBOSE)
112 re_PlayerInfo = re.compile(u"""
113 ^Seat\s(?P<SEAT>[0-9]+):\s
114 (?P<PNAME>.*)\s
115 \((%(LS)s)?(?P<CASH>[.0-9]+)\sin\schips\)""" % substitutions,
116 re.MULTILINE|re.VERBOSE)
118 re_HandInfo = re.compile("""
119 ^Table\s\'(?P<TABLE>[\/,\.\-\ &%\$\#a-zA-Z\d\'\(\)]+)\'\s
120 ((?P<MAX>\d+)-max\s)?
121 (?P<PLAY>\(Play\sMoney\)\s)?
122 (Seat\s\#(?P<BUTTON>\d+)\sis\sthe\sbutton)?""",
123 re.MULTILINE|re.VERBOSE)
125 re_SplitHands = re.compile('\n\n\n+')
126 re_TailSplitHands = re.compile('(\n\n\n+)')
127 re_Button = re.compile('Seat #(?P<BUTTON>\d+) is the button', re.MULTILINE)
128 re_Board = re.compile(r"Board \[(?P<FLOP>\S\S\S? \S\S\S? \S\S\S?)?\s?(?P<TURN>\S\S\S?)?\s?(?P<RIVER>\S\S\S?)?\]")
130 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]+)""", re.MULTILINE)
132 re_PostSB = re.compile(r"^%(PLYR)s: posts small blind (%(LS)s)?(?P<SB>[.0-9]+)" % substitutions, re.MULTILINE)
133 re_PostBB = re.compile(r"^%(PLYR)s: posts big blind (%(LS)s)?(?P<BB>[.0-9]+)" % substitutions, re.MULTILINE)
134 re_Antes = re.compile(r"^%(PLYR)s: posts the ante (%(LS)s)?(?P<ANTE>[.0-9]+)" % substitutions, re.MULTILINE)
135 re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for (%(LS)s)?(?P<BRINGIN>[.0-9]+)" % substitutions, re.MULTILINE)
136 re_PostBoth = re.compile(r"^%(PLYR)s: posts small \& big blinds (%(LS)s)?(?P<SBBB>[.0-9]+)" % substitutions, re.MULTILINE)
137 re_HeroCards = re.compile(r"^Dealt to %(PLYR)s(?: \[(?P<OLDCARDS>.+?)\])?( \[(?P<NEWCARDS>.+?)\])" % substitutions, re.MULTILINE)
138 re_Action = re.compile(r"""
139 ^%(PLYR)s:(?P<ATYPE>\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat)
140 (\s(%(LS)s)?(?P<BET>[.\d]+))?(\sto\s(%(LS)s)?(?P<BETTO>[.\d]+))? # the number discarded goes in <BET>
141 \s*(and\sis\sall.in)?
142 (and\shas\sreached\sthe\s[(%(LS)s)?\d\.]+\scap)?
143 (\son|\scards?)?
144 (\s\[(?P<CARDS>.+?)\])?\s*$"""
145 % substitutions, re.MULTILINE|re.VERBOSE)
146 re_ShowdownAction = re.compile(r"^%s: shows (?P<CARDS>.*)" % substitutions['PLYR'], re.MULTILINE)
147 re_sitsOut = re.compile("^%s sits out" % substitutions['PLYR'], re.MULTILINE)
148 re_JoinsTable = re.compile("^.+ joins the table at seat #\d+", re.MULTILINE)
149 re_ShownCards = re.compile("^Seat (?P<SEAT>[0-9]+): %s (\(.*\) )?(?P<SHOWED>showed|mucked) \[(?P<CARDS>.*)\]( and won \([.\d]+\))?" % substitutions['PLYR'], re.MULTILINE)
150 re_CollectPot = re.compile(r"Seat (?P<SEAT>[0-9]+): %(PLYR)s (collected|showed \[.*\] and won) \((%(LS)s)?(?P<POT>[.\d]+)\)" % substitutions, re.MULTILINE)
151 re_WinningRankOne = re.compile(u"^%(PLYR)s wins the tournament and receives (%(LS)s)?(?P<AMT>[\.0-9]+) - congratulations!$" % substitutions, re.MULTILINE)
152 re_WinningRankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place and received (%(LS)s)?(?P<AMT>[.0-9]+)\.$" % substitutions, re.MULTILINE)
153 re_RankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place$" % substitutions, re.MULTILINE)
155 def compilePlayerRegexs(self, hand):
156 pass
158 def readSupportedGames(self):
159 return [["ring", "hold", "nl"],
160 ["ring", "hold", "pl"],
161 ["ring", "hold", "fl"],
163 ["ring", "stud", "fl"],
165 ["ring", "draw", "fl"],
166 ["ring", "draw", "pl"],
167 ["ring", "draw", "nl"],
169 ["tour", "hold", "nl"],
170 ["tour", "hold", "pl"],
171 ["tour", "hold", "fl"],
173 ["tour", "stud", "fl"],
175 ["tour", "draw", "fl"],
176 ["tour", "draw", "pl"],
177 ["tour", "draw", "nl"],
180 def determineGameType(self, handText):
181 info = {}
182 m = self.re_GameInfo.search(handText)
183 if not m:
184 # BetOnline starts writing the hh the moment you sit down.
185 # Test if the hh contains the join line, and throw a partial if so.
186 m2 = self.re_JoinsTable.search(handText)
187 if not m2:
188 tmp = handText[0:200]
189 log.error(_("BetOnlineToFpdb.determineGameType: '%s'") % tmp)
190 raise FpdbParseError
191 else:
192 raise FpdbHandPartial("BetOnlineToFpdb.determineGameType: " + _("Partial hand history: 'Player joining table'"))
194 mg = m.groupdict()
195 if mg['LIMIT']:
196 info['limitType'] = self.limits[mg['LIMIT']]
197 else:
198 info['limitType'] = self.limits['No Limit']
199 if 'GAME' in mg:
200 (info['base'], info['category']) = self.games[mg['GAME']]
201 if 'SB' in mg:
202 info['sb'] = mg['SB']
203 if 'BB' in mg:
204 info['bb'] = mg['BB']
205 if 'CURRENCY' in mg:
206 info['currency'] = self.currencies[mg['CURRENCY']]
207 if 'MIXED' in mg:
208 if mg['MIXED'] is not None: info['mix'] = self.mixes[mg['MIXED']]
210 if 'TOURNO' in mg and mg['TOURNO'] is None:
211 info['type'] = 'ring'
212 else:
213 info['type'] = 'tour'
215 if info['limitType'] == 'fl' and info['bb'] is not None and info['type'] == 'ring':
216 try:
217 info['sb'] = self.Lim_Blinds[mg['BB']][0]
218 info['bb'] = self.Lim_Blinds[mg['BB']][1]
219 except KeyError:
220 tmp = handText[0:200]
221 log.error(_("BetOnlineToFpdb.determineGameType: Lim_Blinds has no lookup for '%s' - '%s'") % (mg['BB'], tmp))
222 raise FpdbParseError
224 return info
226 def readHandInfo(self, hand):
227 info = {}
228 m = self.re_HandInfo.search(hand.handText,re.DOTALL)
229 m2 = self.re_GameInfo.search(hand.handText)
230 if m is None or m2 is None:
231 tmp = hand.handText[0:200]
232 log.error(_("BetOnlineToFpdb.readHandInfo: '%s'") % tmp)
233 raise FpdbParseError
235 info.update(m.groupdict())
236 info.update(m2.groupdict())
238 log.debug("readHandInfo: %s" % info)
239 for key in info:
240 if key == 'DATETIME':
241 #2008/11/12 10:00:48 CET [2008/11/12 4:00:48 ET] # (both dates are parsed so ET date overrides the other)
242 #2008/08/17 - 01:14:43 (ET)
243 #2008/09/07 06:23:14 ET
244 m1 = self.re_DateTime.finditer(info[key])
245 datetimestr = "2000/01/01 00:00:00" # default used if time not found
246 for a in m1:
247 datetimestr = "%s/%s/%s %s:%s:%s" % (a.group('Y'), a.group('M'),a.group('D'),a.group('H'),a.group('MIN'),'00')
248 #tz = a.group('TZ') # just assume ET??
249 #print " tz = ", tz, " datetime =", datetimestr
250 hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
251 hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, "ET", "UTC")
252 if key == 'HID':
253 hand.handid = info[key]
254 if key == 'TOURNO':
255 hand.tourNo = info[key]
256 if key == 'BUYIN':
257 if hand.tourNo!=None:
258 #print "DEBUG: info['BUYIN']: %s" % info['BUYIN']
259 #print "DEBUG: info['BIAMT']: %s" % info['BIAMT']
260 #print "DEBUG: info['BIRAKE']: %s" % info['BIRAKE']
261 #print "DEBUG: info['BOUNTY']: %s" % info['BOUNTY']
262 if not info[key] or info[key] == 'Freeroll':
263 hand.buyin = 0
264 hand.fee = 0
265 hand.buyinCurrency = "FREE"
266 else:
267 if info[key].find("$")!=-1:
268 hand.buyinCurrency="USD"
269 elif info[key].find(u"€")!=-1:
270 hand.buyinCurrency="EUR"
271 elif info[key].find("FPP")!=-1:
272 hand.buyinCurrency="PSFP"
273 elif re.match("^[0-9+]*$", info[key]):
274 hand.buyinCurrency="play"
275 else:
276 #FIXME: handle other currencies, play money
277 raise FpdbParseError(_("BetOnlineToFpdb.readHandInfo: Failed to detect currency.") + " " + _("Hand ID") + ": %s: '%s'" % (hand.handid, info[key]))
279 info['BIAMT'] = info['BIAMT'].strip(u'$€FPP')
281 if hand.buyinCurrency!="PSFP":
282 if info['BOUNTY'] != None:
283 # There is a bounty, Which means we need to switch BOUNTY and BIRAKE values
284 tmp = info['BOUNTY']
285 info['BOUNTY'] = info['BIRAKE']
286 info['BIRAKE'] = tmp
287 info['BOUNTY'] = info['BOUNTY'].strip(u'$€') # Strip here where it isn't 'None'
288 hand.koBounty = int(100*Decimal(info['BOUNTY']))
289 hand.isKO = True
290 else:
291 hand.isKO = False
293 info['BIRAKE'] = info['BIRAKE'].strip(u'$€')
295 hand.buyin = int(100*Decimal(info['BIAMT']))
296 hand.fee = int(100*Decimal(info['BIRAKE']))
297 else:
298 hand.buyin = int(Decimal(info['BIAMT']))
299 hand.fee = 0
300 if key == 'LEVEL':
301 hand.level = info[key]
303 if key == 'TABLE':
304 if hand.tourNo != None:
305 hand.tablename = re.split("-", info[key])[1]
306 else:
307 hand.tablename = info[key]
308 if key == 'BUTTON':
309 hand.buttonpos = info[key]
310 if key == 'MAX' and info[key] != None:
311 hand.maxseats = int(info[key])
313 if key == 'PLAY' and info['PLAY'] is not None:
314 # hand.currency = 'play' # overrides previously set value
315 hand.gametype['currency'] = 'play'
316 if not self.re_Board.search(hand.handText):
317 raise FpdbHandPartial("readHandInfo: " + _("Partial hand history") + ": '%s'" % hand.handid)
319 def readButton(self, hand):
320 m = self.re_Button.search(hand.handText)
321 if m:
322 hand.buttonpos = int(m.group('BUTTON'))
323 else:
324 log.info('readButton: ' + _('not found'))
326 def readPlayerStacks(self, hand):
327 log.debug("readPlayerStacks")
328 m = self.re_PlayerInfo.finditer(hand.handText)
329 for a in m:
330 hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH'))
332 def markStreets(self, hand):
334 # There is no marker between deal and draw in Stars single draw games
335 # this upsets the accounting, incorrectly sets handsPlayers.cardxx and
336 # in consequence the mucked-display is incorrect.
337 # Attempt to fix by inserting a DRAW marker into the hand text attribute
339 if hand.gametype['category'] in ('27_1draw', 'fivedraw'):
340 # isolate the first discard/stand pat line (thanks Carl for the regex)
341 discard_split = re.split(r"(?:(.+(?: stands pat|: discards).+))", hand.handText,re.DOTALL)
342 if len(hand.handText) == len(discard_split[0]):
343 # handText was not split, no DRAW street occurred
344 pass
345 else:
346 # DRAW street found, reassemble, with DRAW marker added
347 discard_split[0] += "*** DRAW ***\r\n"
348 hand.handText = ""
349 for i in discard_split:
350 hand.handText += i
352 # PREFLOP = ** Dealing down cards **
353 # This re fails if, say, river is missing; then we don't get the ** that starts the river.
354 if hand.gametype['base'] in ("hold"):
355 m = re.search(r"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
356 r"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S\S? \S\S\S? \S\S\S?\].+(?=\*\*\* TURN \*\*\*)|.+))?"
357 r"(\*\*\* TURN \*\*\* \[\S\S\S? \S\S\S? \S\S\S?](?P<TURN>\[\S\S\S?\].+(?=\*\*\* RIVER \*\*\*)|.+))?"
358 r"(\*\*\* RIVER \*\*\* \[\S\S\S? \S\S\S? \S\S\S? \S\S\S?](?P<RIVER>\[\S\S\S?\].+))?", hand.handText,re.DOTALL)
359 m2 = self.re_Board.search(hand.handText)
360 if m and m2:
361 if m2.group('FLOP') and not m.group('FLOP'):
362 m = re.search(r"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=Board )|.+)"
363 r"(Board \[(?P<FLOP>\S\S\S? \S\S\S? \S\S\S?)?\s?(?P<TURN>\S\S\S?)?\s?(?P<RIVER>\S\S\S?)?\])?", hand.handText,re.DOTALL)
364 elif m2.group('TURN') and not m.group('TURN'):
365 m = re.search(r"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
366 r"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S\S? \S\S\S? \S\S\S?\].+(?=Board )|.+))?"
367 r"(Board \[(?P<BFLOP>\S\S\S? \S\S\S? \S\S\S?)?\s?(?P<TURN>\S\S\S?)?\s?(?P<RIVER>\S\S\S?)?\])?", hand.handText,re.DOTALL)
368 elif m2.group('RIVER') and not m.group('RIVER'):
369 m = re.search(r"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
370 r"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S\S? \S\S\S? \S\S\S?\].+(?=\*\*\* TURN \*\*\*)|.+))?"
371 r"(\*\*\* TURN \*\*\* \[\S\S\S? \S\S\S? \S\S\S?](?P<TURN>\[\S\S\S?\].+(?=Board )|.+))?"
372 r"(Board \[(?P<BFLOP>\S\S\S? \S\S\S? \S\S\S?)?\s?(?P<BTURN>\S\S\S?)?\s?(?P<RIVER>\S\S\S?)?\])?", hand.handText,re.DOTALL)
373 elif hand.gametype['base'] in ("stud"):
374 m = re.search(r"(?P<ANTES>.+(?=\*\*\* 3rd STREET \*\*\*)|.+)"
375 r"(\*\*\* 3rd STREET \*\*\*(?P<THIRD>.+(?=\*\*\* 4th STREET \*\*\*)|.+))?"
376 r"(\*\*\* 4th STREET \*\*\*(?P<FOURTH>.+(?=\*\*\* 5th STREET \*\*\*)|.+))?"
377 r"(\*\*\* 5th STREET \*\*\*(?P<FIFTH>.+(?=\*\*\* 6th STREET \*\*\*)|.+))?"
378 r"(\*\*\* 6th STREET \*\*\*(?P<SIXTH>.+(?=\*\*\* RIVER \*\*\*)|.+))?"
379 r"(\*\*\* RIVER \*\*\*(?P<SEVENTH>.+))?", hand.handText,re.DOTALL)
380 elif hand.gametype['base'] in ("draw"):
381 if hand.gametype['category'] in ('27_1draw', 'fivedraw'):
382 m = re.search(r"(?P<PREDEAL>.+(?=\*\*\* DEALING HANDS \*\*\*)|.+)"
383 r"(\*\*\* DEALING HANDS \*\*\*(?P<DEAL>.+(?=\*\*\* DRAW \*\*\*)|.+))?"
384 r"(\*\*\* DRAW \*\*\*(?P<DRAWONE>.+))?", hand.handText,re.DOTALL)
385 else:
386 m = re.search(r"(?P<PREDEAL>.+(?=\*\*\* DEALING HANDS \*\*\*)|.+)"
387 r"(\*\*\* DEALING HANDS \*\*\*(?P<DEAL>.+(?=\*\*\* FIRST DRAW \*\*\*)|.+))?"
388 r"(\*\*\* FIRST DRAW \*\*\*(?P<DRAWONE>.+(?=\*\*\* SECOND DRAW \*\*\*)|.+))?"
389 r"(\*\*\* SECOND DRAW \*\*\*(?P<DRAWTWO>.+(?=\*\*\* THIRD DRAW \*\*\*)|.+))?"
390 r"(\*\*\* THIRD DRAW \*\*\*(?P<DRAWTHREE>.+))?", hand.handText,re.DOTALL)
391 hand.addStreets(m)
392 #if m3 and m2:
393 # if m2.group('RIVER') and not m3.group('RIVER'):
394 # print hand.streets
396 def readCommunityCards(self, hand, street): # street has been matched by markStreets, so exists in this hand
397 m = self.re_Board.search(hand.handText)
398 if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
399 if m:
400 if m.group(street):
401 cards = m.group(street).split(' ')
402 cards = [c.replace("10", "T") for c in cards]
403 hand.setCommunityCards(street, cards)
405 def readAntes(self, hand):
406 log.debug(_("reading antes"))
407 m = self.re_Antes.finditer(hand.handText)
408 for player in m:
409 #~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
410 hand.addAnte(player.group('PNAME'), player.group('ANTE'))
412 def readBringIn(self, hand):
413 m = self.re_BringIn.search(hand.handText,re.DOTALL)
414 if m:
415 #~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
416 hand.addBringIn(m.group('PNAME'), m.group('BRINGIN'))
418 def readBlinds(self, hand):
419 liveBlind = True
420 for a in self.re_PostSB.finditer(hand.handText):
421 if liveBlind:
422 hand.addBlind(a.group('PNAME'), 'small blind', a.group('SB'))
423 liveBlind = False
424 else:
425 # Post dead blinds as ante
426 hand.addBlind(a.group('PNAME'), 'secondsb', a.group('SB'))
427 for a in self.re_PostBB.finditer(hand.handText):
428 hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
429 for a in self.re_PostBoth.finditer(hand.handText):
430 hand.addBlind(a.group('PNAME'), 'both', a.group('SBBB'))
432 def readHeroCards(self, hand):
433 # streets PREFLOP, PREDRAW, and THIRD are special cases beacause
434 # we need to grab hero's cards
435 for street in ('PREFLOP', 'DEAL'):
436 if street in hand.streets.keys():
437 m = self.re_HeroCards.finditer(hand.streets[street])
438 for found in m:
439 # if m == None:
440 # hand.involved = False
441 # else:
442 hand.hero = found.group('PNAME')
443 newcards = found.group('NEWCARDS').split(' ')
444 newcards = [n.replace("10", "T") for n in newcards]
445 hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
447 for street, text in hand.streets.iteritems():
448 if not text or street in ('PREFLOP', 'DEAL'): continue # already done these
449 m = self.re_HeroCards.finditer(hand.streets[street])
450 for found in m:
451 player = found.group('PNAME')
452 if found.group('NEWCARDS') is None:
453 newcards = []
454 else:
455 newcards = found.group('NEWCARDS').split(' ')
456 newcards = [n.replace("10", "T") for n in newcards]
457 if found.group('OLDCARDS') is None:
458 oldcards = []
459 else:
460 oldcards = found.group('OLDCARDS').split(' ')
461 oldcards = [o.replace("10", "T") for o in oldcards]
462 if street == 'THIRD' and len(newcards) == 3: # hero in stud game
463 hand.hero = player
464 hand.dealt.add(player) # need this for stud??
465 hand.addHoleCards(street, player, closed=newcards[0:2], open=[newcards[2]], shown=False, mucked=False, dealt=False)
466 else:
467 hand.addHoleCards(street, player, open=newcards, closed=oldcards, shown=False, mucked=False, dealt=False)
470 def readAction(self, hand, street):
471 m = self.re_Action.finditer(hand.streets[street])
472 for action in m:
473 acts = action.groupdict()
474 #print "DEBUG: acts: %s" %acts
475 if action.group('PNAME') != 'Unknown player':
476 if action.group('ATYPE') == ' folds':
477 hand.addFold( street, action.group('PNAME'))
478 elif action.group('ATYPE') == ' checks':
479 hand.addCheck( street, action.group('PNAME'))
480 elif action.group('ATYPE') == ' calls':
481 hand.addCall( street, action.group('PNAME'), action.group('BET') )
482 elif action.group('ATYPE') == ' raises':
483 hand.addCallandRaise( street, action.group('PNAME'), action.group('BET') )
484 elif action.group('ATYPE') == ' bets':
485 hand.addBet( street, action.group('PNAME'), action.group('BET') )
486 elif action.group('ATYPE') == ' discards':
487 hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('CARDS'))
488 elif action.group('ATYPE') == ' stands pat':
489 hand.addStandsPat( street, action.group('PNAME'), action.group('CARDS'))
490 else:
491 print (_("DEBUG:") + " " + _("Unimplemented %s: '%s' '%s'") % ("readAction", action.group('PNAME'), action.group('ATYPE')))
494 def readShowdownActions(self, hand):
495 # TODO: pick up mucks also??
496 for shows in self.re_ShowdownAction.finditer(hand.handText):
497 cards = shows.group('CARDS').split(' ')
498 cards = [c.replace("10", "T") for c in cards]
499 hand.addShownCards(cards, shows.group('PNAME'))
501 for winningrankone in self.re_WinningRankOne.finditer(hand.handText):
502 hand.addPlayerRank (winningrankone.group('PNAME'),int(100*Decimal(winningrankone.group('AMT'))),1)
504 for winningrankothers in self.re_WinningRankOther.finditer(hand.handText):
505 hand.addPlayerRank (winningrankothers.group('PNAME'),int(100*Decimal(winningrankothers.group('AMT'))),winningrankothers.group('RANK'))
507 for rankothers in self.re_RankOther.finditer(hand.handText):
508 hand.addPlayerRank (rankothers.group('PNAME'),0,rankothers.group('RANK'))
510 def readCollectPot(self,hand):
511 for m in self.re_CollectPot.finditer(hand.handText):
512 hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT'))
514 def readShownCards(self,hand):
515 for m in self.re_ShownCards.finditer(hand.handText):
516 if m.group('CARDS') is not None:
517 cards = m.group('CARDS')
518 cards = cards.split(' ') # needs to be a list, not a set--stud needs the order
519 cards = [c.replace("10", "T") for c in cards]
520 (shown, mucked) = (False, False)
521 if m.group('SHOWED') == "showed": shown = True
522 elif m.group('SHOWED') == "mucked": mucked = True
524 #print "DEBUG: hand.addShownCards(%s, %s, %s, %s)" %(cards, m.group('PNAME'), shown, mucked)
525 hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=shown, mucked=mucked, string=None)