2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/python
|
2010-07-07 07:06:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#Copyright 2008-2010 Steffen Schaumburg
|
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#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 Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
|
|
|
|
|
|
|
"""pokerstars-specific summary parsing code"""
|
|
|
|
|
2010-07-07 08:05:42 +02:00
|
|
|
from decimal import Decimal
|
2010-07-08 21:41:27 +02:00
|
|
|
import datetime
|
2010-07-07 08:05:42 +02:00
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
from Exceptions import FpdbParseError
|
2010-07-13 20:37:06 +02:00
|
|
|
from HandHistoryConverter import *
|
2010-07-08 23:31:39 +02:00
|
|
|
import PokerStarsToFpdb
|
2010-07-07 08:05:42 +02:00
|
|
|
from TourneySummary import *
|
2010-07-07 07:06:11 +02:00
|
|
|
|
2010-09-04 07:08:36 +02:00
|
|
|
import locale
|
|
|
|
lang=locale.getdefaultlocale()[0][0:2]
|
|
|
|
if lang=="en":
|
|
|
|
def _(string): return string
|
|
|
|
else:
|
|
|
|
import gettext
|
|
|
|
try:
|
|
|
|
trans = gettext.translation("fpdb", localedir="locale", languages=[lang])
|
|
|
|
trans.install()
|
|
|
|
except IOError:
|
|
|
|
def _(string): return string
|
|
|
|
|
2010-07-07 07:06:11 +02:00
|
|
|
class PokerStarsSummary(TourneySummary):
|
2010-07-13 20:17:15 +02:00
|
|
|
limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
|
|
|
|
games = { # base, category
|
|
|
|
"Hold'em" : ('hold','holdem'),
|
|
|
|
'Omaha' : ('hold','omahahi'),
|
|
|
|
'Omaha Hi/Lo' : ('hold','omahahilo'),
|
|
|
|
'Razz' : ('stud','razz'),
|
|
|
|
'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'),
|
|
|
|
'5 Card Draw' : ('draw','fivedraw')
|
|
|
|
}
|
2010-09-04 10:31:39 +02:00
|
|
|
|
2010-09-04 12:10:25 +02:00
|
|
|
substitutions = {
|
|
|
|
'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
|
|
|
|
'LS' : "\$|\xe2\x82\xac|" # legal currency symbols - Euro(cp1252, utf-8)
|
|
|
|
}
|
|
|
|
|
2010-09-04 10:31:39 +02:00
|
|
|
re_SplitGames = re.compile("^PokerStars")
|
2010-07-13 20:17:15 +02:00
|
|
|
|
2010-09-04 12:10:25 +02:00
|
|
|
re_TourNo = re.compile("\#(?P<TOURNO>[0-9]+),")
|
|
|
|
|
|
|
|
re_TourneyInfo = re.compile(u"""
|
|
|
|
\#(?P<TOURNO>[0-9]+),\s
|
|
|
|
(?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\s
|
2010-09-04 18:55:55 +02:00
|
|
|
(?P<GAME>Hold\'em|Razz|RAZZ|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball|5\sCard\sDraw)\s+
|
|
|
|
(?P<DESC>[ a-zA-Z]+\s+)?
|
|
|
|
(Buy-In:\s\$(?P<BUYIN>[.0-9]+)(\/\$(?P<FEE>[.0-9]+))?\s+)?
|
|
|
|
(?P<ENTRIES>[0-9]+)\splayers\s+
|
|
|
|
(\$?(?P<ADDED>[.\d]+)\sadded\sto\sthe\sprize\spool\sby\sPokerStars\.com\s+)?
|
|
|
|
(Total\sPrize\sPool:\s\$?(?P<PRIZEPOOL>[.0-9]+)\s+)?
|
2010-09-04 14:06:24 +02:00
|
|
|
(Target\sTournament\s.*)?
|
2010-09-04 12:10:25 +02:00
|
|
|
Tournament\sstarted\s-\s
|
|
|
|
(?P<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\-\s]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)\s?\(?(?P<TZ>[A-Z]+)\)\s
|
2010-09-04 14:06:24 +02:00
|
|
|
""" % substitutions ,re.VERBOSE|re.MULTILINE|re.DOTALL)
|
2010-09-04 12:10:25 +02:00
|
|
|
|
|
|
|
re_Currency = re.compile(u"""(?P<CURRENCY>[%(LS)s]|FPP)""" % substitutions)
|
|
|
|
|
2010-09-09 11:48:19 +02:00
|
|
|
re_Player = re.compile(u"""(?P<RANK>[0-9]+):\s(?P<NAME>.*)\s\(.*\),(\s)?(\$(?P<WINNINGS>[0-9]+\.[0-9]+))?(?P<STILLPLAYING>still\splaying)?((?P<TICKET>Tournament\sTicket)\s\(WSOP\sStep\s(?P<LEVEL>\d)\))?\s+?""")
|
2010-09-04 12:10:25 +02:00
|
|
|
|
|
|
|
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]+)")
|
|
|
|
|
2010-07-07 07:06:11 +02:00
|
|
|
re_Entries = re.compile("[0-9]+")
|
|
|
|
re_Prizepool = re.compile("\$[0-9]+\.[0-9]+")
|
2010-07-08 19:46:25 +02:00
|
|
|
re_BuyInFee = re.compile("(?P<BUYIN>[0-9]+\.[0-9]+).*(?P<FEE>[0-9]+\.[0-9]+)")
|
2010-07-11 00:37:25 +02:00
|
|
|
re_FPP = re.compile("(?P<FPP>[0-9]+)\sFPP")
|
|
|
|
#note: the dollar and cent in the below line are currency-agnostic
|
|
|
|
re_Added = re.compile("(?P<DOLLAR>[0-9]+)\.(?P<CENT>[0-9]+)\s(?P<CURRENCY>[A-Z]+)(\sadded\sto\sthe\sprize\spool\sby\sPokerStars)")
|
2010-07-13 21:17:40 +02:00
|
|
|
re_DateTimeET = 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]+)")
|
2010-07-13 20:17:15 +02:00
|
|
|
re_GameInfo = re.compile(u""".+(?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\s(?P<GAME>Hold\'em|Razz|RAZZ|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball|5\sCard\sDraw)""")
|
2010-07-07 07:06:11 +02:00
|
|
|
|
|
|
|
def parseSummary(self):
|
|
|
|
lines=self.summaryText.splitlines()
|
|
|
|
|
|
|
|
self.tourNo = self.re_TourNo.findall(lines[0])[0][1:-1] #ignore game and limit type as thats not recorded
|
2010-07-13 20:17:15 +02:00
|
|
|
|
|
|
|
result=self.re_GameInfo.search(lines[0])
|
|
|
|
result=result.groupdict()
|
|
|
|
self.gametype['limitType']=self.limits[result['LIMIT']]
|
2010-07-15 01:58:54 +02:00
|
|
|
self.gametype['category']=self.games[result['GAME']][1]
|
2010-07-07 07:06:11 +02:00
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
if lines[1].find("$")!=-1: #TODO: move this into a method and call that from PokerStarsToFpdb.py:269 if hand.buyinCurrency=="USD" etc.
|
2010-07-08 19:46:25 +02:00
|
|
|
self.currency="USD"
|
|
|
|
elif lines[1].find(u"€")!=-1:
|
|
|
|
self.currency="EUR"
|
2010-07-11 00:37:25 +02:00
|
|
|
elif lines[1].find("FPP")!=-1:
|
|
|
|
self.currency="PSFP"
|
2010-07-08 19:46:25 +02:00
|
|
|
else:
|
2010-08-15 19:46:10 +02:00
|
|
|
raise FpdbParseError(_("didn't recognise buyin currency in:")+lines[1])
|
2010-07-08 19:46:25 +02:00
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
if self.currency=="USD" or self.currency=="EUR":
|
|
|
|
result=self.re_BuyInFee.search(lines[1])
|
|
|
|
result=result.groupdict()
|
|
|
|
self.buyin=int(100*Decimal(result['BUYIN']))
|
|
|
|
self.fee=int(100*Decimal(result['FEE']))
|
|
|
|
elif self.currency=="PSFP":
|
|
|
|
result=self.re_FPP.search(lines[1])
|
|
|
|
result=result.groupdict()
|
|
|
|
self.buyin=int(Decimal(result['FPP']))
|
|
|
|
self.fee=0
|
2010-07-07 07:06:11 +02:00
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
currentLine=2
|
|
|
|
self.entries = self.re_Entries.findall(lines[currentLine])[0]
|
|
|
|
currentLine+=1 #note that I chose to make the code keep state (the current line number)
|
|
|
|
#as that means it'll fail rather than silently skip potentially valuable information
|
2010-07-11 01:55:15 +02:00
|
|
|
#print "after entries lines[currentLine]", lines[currentLine]
|
2010-09-04 12:10:25 +02:00
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
result=self.re_Added.search(lines[currentLine])
|
|
|
|
if result:
|
|
|
|
result=result.groupdict()
|
|
|
|
self.added=100*int(Decimal(result['DOLLAR']))+int(Decimal(result['CENT']))
|
|
|
|
self.addedCurrency=result['CURRENCY']
|
|
|
|
currentLine+=1
|
2010-07-17 04:37:15 +02:00
|
|
|
else:
|
|
|
|
self.added=0
|
|
|
|
self.addedCurrency="NA"
|
2010-07-11 01:55:15 +02:00
|
|
|
#print "after added/entries lines[currentLine]", lines[currentLine]
|
2010-09-04 12:10:25 +02:00
|
|
|
|
2010-07-11 01:39:52 +02:00
|
|
|
result=self.re_Prizepool.findall(lines[currentLine])
|
|
|
|
if result:
|
|
|
|
self.prizepool = result[0]
|
|
|
|
self.prizepool = self.prizepool[1:-3]+self.prizepool[-2:]
|
|
|
|
currentLine+=1
|
2010-07-11 00:37:25 +02:00
|
|
|
#print "after prizepool lines[currentLine]", lines[currentLine]
|
2010-07-07 07:06:11 +02:00
|
|
|
|
2010-07-13 21:17:40 +02:00
|
|
|
useET=False
|
2010-07-11 00:37:25 +02:00
|
|
|
result=self.re_DateTime.search(lines[currentLine])
|
2010-07-13 21:17:40 +02:00
|
|
|
if not result:
|
2010-08-15 19:46:10 +02:00
|
|
|
print _("in not result starttime")
|
2010-07-13 21:17:40 +02:00
|
|
|
useET=True
|
|
|
|
result=self.re_DateTimeET.search(lines[currentLine])
|
2010-07-08 21:41:27 +02:00
|
|
|
result=result.groupdict()
|
|
|
|
datetimestr = "%s/%s/%s %s:%s:%s" % (result['Y'], result['M'],result['D'],result['H'],result['MIN'],result['S'])
|
|
|
|
self.startTime= datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
|
2010-07-13 20:37:06 +02:00
|
|
|
self.startTime = HandHistoryConverter.changeTimezone(self.startTime, "ET", "UTC")
|
2010-07-11 00:37:25 +02:00
|
|
|
currentLine+=1
|
2010-09-04 12:10:25 +02:00
|
|
|
|
2010-07-13 21:17:40 +02:00
|
|
|
if useET:
|
|
|
|
result=self.re_DateTimeET.search(lines[currentLine])
|
|
|
|
else:
|
|
|
|
result=self.re_DateTime.search(lines[currentLine])
|
2010-07-11 01:39:52 +02:00
|
|
|
if result:
|
|
|
|
result=result.groupdict()
|
|
|
|
datetimestr = "%s/%s/%s %s:%s:%s" % (result['Y'], result['M'],result['D'],result['H'],result['MIN'],result['S'])
|
|
|
|
self.endTime= datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
|
2010-07-13 21:17:40 +02:00
|
|
|
self.endTime = HandHistoryConverter.changeTimezone(self.endTime, "ET", "UTC")
|
|
|
|
currentLine+=1
|
2010-07-07 07:06:11 +02:00
|
|
|
|
2010-07-11 01:55:15 +02:00
|
|
|
if lines[currentLine].find("Tournament is still in progress")!=-1:
|
|
|
|
currentLine+=1
|
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
for i in range(currentLine,len(lines)-2): #lines with rank and winnings info
|
2010-07-07 07:06:11 +02:00
|
|
|
if lines[i].find(":")==-1:
|
|
|
|
break
|
2010-07-07 08:05:42 +02:00
|
|
|
result=self.re_Player.search(lines[i])
|
|
|
|
result=result.groupdict()
|
|
|
|
rank=result['RANK']
|
|
|
|
name=result['NAME']
|
|
|
|
winnings=result['WINNINGS']
|
2010-09-04 12:10:25 +02:00
|
|
|
|
2010-07-07 07:06:11 +02:00
|
|
|
if winnings:
|
2010-07-07 08:05:42 +02:00
|
|
|
winnings=int(100*Decimal(winnings))
|
2010-07-07 07:06:11 +02:00
|
|
|
else:
|
|
|
|
winnings=0
|
|
|
|
|
2010-07-11 01:55:15 +02:00
|
|
|
if result['STILLPLAYING']:
|
|
|
|
#print "stillplaying"
|
|
|
|
rank=None
|
|
|
|
winnings=None
|
|
|
|
|
2010-07-11 00:37:25 +02:00
|
|
|
self.addPlayer(rank, name, winnings, self.currency, None, None, None)#TODO: currency, ko/addon/rebuy count -> need examples!
|
2010-07-07 07:06:11 +02:00
|
|
|
#end def parseSummary
|
2010-09-04 12:10:25 +02:00
|
|
|
|
2010-09-04 10:31:39 +02:00
|
|
|
def parseSummaryFile(self):
|
2010-09-04 12:10:25 +02:00
|
|
|
m = self.re_TourneyInfo.search(self.summaryText)
|
2010-09-04 14:06:24 +02:00
|
|
|
if m == None:
|
|
|
|
tmp = self.summaryText[0:200]
|
2010-09-04 12:10:25 +02:00
|
|
|
log.error(_("parseSummaryFile: Unable to recognise Tourney Info: '%s'") % tmp)
|
|
|
|
log.error(_("parseSummaryFile: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("Unable to recognise Tourney Info: '%s'") % tmp)
|
|
|
|
|
2010-09-04 14:06:24 +02:00
|
|
|
#print "DEBUG: m.groupdict(): %s" % m.groupdict()
|
|
|
|
|
2010-09-04 12:10:25 +02:00
|
|
|
mg = m.groupdict()
|
|
|
|
if 'TOURNO' in mg: self.tourNo = mg['TOURNO']
|
|
|
|
if 'LIMIT' in mg: self.gametype['limitType'] = self.limits[mg['LIMIT']]
|
|
|
|
if 'GAME' in mg: self.gametype['category'] = self.games[mg['GAME']][1]
|
2010-09-04 14:06:24 +02:00
|
|
|
if mg['BUYIN'] != None:
|
|
|
|
self.buyin = int(100*Decimal(mg['BUYIN']))
|
|
|
|
if mg['FEE'] != None:
|
|
|
|
self.fee = int(100*Decimal(mg['FEE']))
|
2010-09-04 12:10:25 +02:00
|
|
|
if 'PRIZEPOOL' in mg: self.prizepool = mg['PRIZEPOOL']
|
|
|
|
if 'ENTRIES' in mg: self.entries = mg['ENTRIES']
|
|
|
|
|
|
|
|
datetimestr = "%s/%s/%s %s:%s:%s" % (mg['Y'], mg['M'], mg['D'], mg['H'], mg['MIN'], mg['S'])
|
|
|
|
self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
|
|
|
|
|
|
|
|
if 'TZ' in mg:
|
|
|
|
self.startTime = HandHistoryConverter.changeTimezone(self.startTime, mg['TZ'], "UTC")
|
|
|
|
|
|
|
|
|
|
|
|
m = self.re_Currency.search(self.summaryText)
|
2010-09-04 14:06:24 +02:00
|
|
|
if m == None:
|
2010-09-04 12:10:25 +02:00
|
|
|
log.error(_("parseSummaryFile: Unable to locate currency"))
|
|
|
|
log.error(_("parseSummaryFile: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("Unable to locate currency"))
|
2010-09-04 14:06:24 +02:00
|
|
|
#print "DEBUG: m.groupdict(): %s" % m.groupdict()
|
2010-09-04 12:10:25 +02:00
|
|
|
|
|
|
|
mg = m.groupdict()
|
|
|
|
if mg['CURRENCY'] == "$": self.currency = "USD"
|
|
|
|
elif mg['CURRENCY'] == u"€": self.currency="EUR"
|
|
|
|
elif mg['CURRENCY'] == "FPP": self.currency="PSFP"
|
|
|
|
|
|
|
|
m = self.re_Player.finditer(self.summaryText)
|
|
|
|
for a in m:
|
|
|
|
mg = a.groupdict()
|
2010-09-04 14:06:24 +02:00
|
|
|
#print "DEBUG: a.groupdict(): %s" % mg
|
2010-09-04 12:10:25 +02:00
|
|
|
name = mg['NAME']
|
|
|
|
rank = mg['RANK']
|
|
|
|
winnings = 0
|
|
|
|
|
|
|
|
if 'WINNINGS' in mg and mg['WINNINGS'] != None:
|
|
|
|
winnings = int(100*Decimal(mg['WINNINGS']))
|
|
|
|
|
2010-09-04 14:06:24 +02:00
|
|
|
if 'STILLPLAYING' in mg and mg['STILLPLAYING'] != None:
|
2010-09-04 12:10:25 +02:00
|
|
|
#print "stillplaying"
|
|
|
|
rank=None
|
|
|
|
winnings=None
|
|
|
|
|
2010-09-04 14:36:31 +02:00
|
|
|
if 'TICKET' and mg['TICKET'] != None:
|
2010-09-05 16:08:27 +02:00
|
|
|
#print "Tournament Ticket Level %s" % mg['LEVEL']
|
|
|
|
step_values = {
|
|
|
|
'1' : '750', # Step 1 - $7.50 USD
|
|
|
|
'2' : '2750', # Step 2 - $27.00 USD
|
|
|
|
'3' : '8200', # Step 3 - $82.00 USD
|
|
|
|
'4' : '21500', # Step 4 - $215.00 USD
|
|
|
|
'5' : '70000', # Step 5 - $700.00 USD
|
|
|
|
'6' : '210000', # Step 6 - $2100.00 USD
|
|
|
|
}
|
|
|
|
winnings = step_values[mg['LEVEL']]
|
2010-09-04 14:36:31 +02:00
|
|
|
|
2010-09-04 12:10:25 +02:00
|
|
|
#TODO: currency, ko/addon/rebuy count -> need examples!
|
2010-09-04 14:06:24 +02:00
|
|
|
#print "DEBUG: addPlayer(%s, %s, %s, %s, None, None, None)" %(rank, name, winnings, self.currency)
|
|
|
|
#print "DEBUG: self.buyin: %s self.fee %s" %(self.buyin, self.fee)
|
2010-09-04 12:10:25 +02:00
|
|
|
self.addPlayer(rank, name, winnings, self.currency, None, None, None)
|
|
|
|
|
2010-09-04 14:06:24 +02:00
|
|
|
#print self
|
2010-09-04 12:10:25 +02:00
|
|
|
|
2010-07-07 08:05:42 +02:00
|
|
|
#end class PokerStarsSummary
|