2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2012 Steffen Schaumburg, Carl Gherardi
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 """pokerstars-specific summary parsing code"""
21 _
= L10n
.get_translation()
23 from decimal_wrapper
import Decimal
26 from Exceptions
import FpdbParseError
27 from HandHistoryConverter
import *
28 import PokerStarsToFpdb
29 from TourneySummary
import *
31 class PokerStarsSummary(TourneySummary
):
33 limits
= { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
34 games
= { # base, category
35 "Hold'em" : ('hold','holdem'),
36 'Omaha' : ('hold','omahahi'),
37 'Omaha Hi/Lo' : ('hold','omahahilo'),
38 'Razz' : ('stud','razz'),
39 'RAZZ' : ('stud','razz'),
40 '7 Card Stud' : ('stud','studhi'),
41 '7 Card Stud Hi/Lo' : ('stud','studhilo'),
42 'Badugi' : ('draw','badugi'),
43 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
44 '5 Card Draw' : ('draw','fivedraw'),
45 'HORSE' : ('mixed','mix_horse'),
46 '8-Game' : ('mixed','mix_8game'),
50 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
51 'LS' : u
"\$|\xe2\x82\xac|\u20AC|" # legal currency symbols - Euro(cp1252, utf-8)
55 re_TourNo
= re
.compile("\#(?P<TOURNO>[0-9]+),")
57 re_TourneyInfo
= re
.compile(u
"""
58 \#(?P<TOURNO>[0-9]+),\s
59 ((?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\s)?
60 (?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|HORSE|8-Game)\s+
61 (?P<DESC>[ a-zA-Z]+\s+)?
62 (Buy-In:\s[%(LS)s]?(?P<BUYIN>[.0-9]+)(\/[%(LS)s](?P<FEE>[.0-9]+))?(?P<CUR>\s(%(LEGAL_ISO)s))?\s+)?
63 (?P<ENTRIES>[0-9]+)\splayers\s+
64 ([%(LS)s]?(?P<ADDED>[.\d]+)(\s(%(LEGAL_ISO)s))?\sadded\sto\sthe\sprize\spool\sby\sPokerStars(\.com)?\s+)?
65 (Total\sPrize\sPool:\s[%(LS)s]?(?P<PRIZEPOOL>[.0-9]+)(\s(%(LEGAL_ISO)s))?\s+)?
66 (Target\sTournament\s.+?\s)?
67 Tournament\sstarted\s+(-\s)?
69 """ % substitutions
,re
.VERBOSE|re
.MULTILINE
)
71 re_Currency
= re
.compile(u
"""(?P<CURRENCY>[%(LS)s]|FPP)""" % substitutions
)
73 re_Player
= re
.compile(u
"""(?P<RANK>[0-9]+):\s(?P<NAME>.*)\s\(.*\),(\s)?((?P<CUR>[%(LS)s])(?P<WINNINGS>[0-9]+\.[0-9]+))?(?P<STILLPLAYING>still\splaying)?((?P<TICKET>Tournament\sTicket)\s\(WSOP\sStep\s(?P<LEVEL>\d)\))?(\s+)?""" % substitutions
)
75 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
)
77 #re_WinningRankOne = re.compile(u"^%(PLYR)s wins the tournament and receives %(CUR)s(?P<AMT>[\.0-9]+) - congratulations!$" % substitutions, re.MULTILINE)
78 #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)
79 #re_RankOther = re.compile(u"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place$" % substitutions, re.MULTILINE)
84 def getSplitRe(self
, head
):
85 re_SplitTourneys
= re
.compile("PokerStars Tournament ")
86 re_HTMLSplitTourneys
= re
.compile("TR id=row_\d+")
87 m
= re
.search("DOCTYPE HTML PUBLIC", head
)
90 return re_HTMLSplitTourneys
91 self
.hhtype
= "summary"
92 return re_SplitTourneys
94 def parseSummary(self
):
95 if self
.hhtype
== "summary":
96 self
.parseSummaryFile()
97 elif self
.hhtype
== "html":
98 self
.parseSummaryHtml()
99 elif self
.hhtype
== "hh":
100 self
.parseSummaryFromHH()
102 raise FpdbParseError(_("parseSummary FAIL"))
104 def parseSummaryFromHH(self
):
105 raise FpdbParseError(_("PokerStarsSummary.parseSummaryHtml: This file format is not yet supported"))
106 # self.entries = Unavailable from HH
107 # self.prizepool = Unavailable from HH
108 # self.startTime = Unreliable from HH (late reg)
109 #obj = getattr(PokerStarsToFpdb, "PokerStars", None)
110 #hhc = obj(self.config, in_path = self.in_path, sitename = None, autostart = False)
112 #self.buyin = int(100*hhc.SnG_Structures[tourneyNameFull]['buyIn'])
113 #self.fee = int(100*hhc.SnG_Structures[tourneyNameFull]['fee'])
118 #self.buyinCurrency =
122 #self.addPlayer(rank, name, winnings, self.currency, rebuyCount, addOnCount, koCount)
124 def parseSummaryHtml(self
):
125 raise FpdbParseError(_("PokerStarsSummary.parseSummaryHtml: This file format is not yet supported"))
126 #from BeautifulSoup import BeautifulSoup
127 #soup = BeautifulSoup(self.summaryText)
128 #h2 = soup.findAll('h2')
131 #tbl = soup.findAll('tr')
134 def parseSummaryFile(self
):
135 m
= self
.re_TourneyInfo
.search(self
.summaryText
)
137 tmp
= self
.summaryText
[0:200]
138 log
.error(_("PokerStarsSummary.parseSummary: '%s'") % tmp
)
141 #print "DEBUG: m.groupdict(): %s" % m.groupdict()
144 if 'TOURNO' in mg
: self
.tourNo
= mg
['TOURNO']
145 if 'LIMIT' in mg
and mg
['LIMIT'] is not None:
146 self
.gametype
['limitType'] = self
.limits
[mg
['LIMIT']]
148 self
.gametype
['limitType'] = 'fl'
149 if 'GAME' in mg
: self
.gametype
['category'] = self
.games
[mg
['GAME']][1]
150 if mg
['BUYIN'] != None:
151 self
.buyin
= int(100*Decimal(self
.clearMoneyString(mg
['BUYIN'])))
152 if mg
['FEE'] != None:
153 self
.fee
= int(100*Decimal(self
.clearMoneyString(mg
['FEE'])))
154 if 'PRIZEPOOL' in mg
:
155 if mg
['PRIZEPOOL'] != None: self
.prizepool
= int(Decimal(self
.clearMoneyString(mg
['PRIZEPOOL'])))
156 if 'ENTRIES' in mg
: self
.entries
= mg
['ENTRIES']
157 if 'DATETIME' in mg
: m1
= self
.re_DateTime
.finditer(mg
['DATETIME'])
158 datetimestr
= "2000/01/01 00:00:00" # default used if time not found
160 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'))
162 self
.startTime
= datetime
.datetime
.strptime(datetimestr
, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
163 self
.startTime
= HandHistoryConverter
.changeTimezone(self
.startTime
, "ET", "UTC")
165 m
= self
.re_Currency
.search(self
.summaryText
)
167 log
.error("PokerStarsSummary.parseSummary: " + _("Unable to locate currency"))
169 #print "DEBUG: m.groupdict(): %s" % m.groupdict()
172 if mg
['CURRENCY'] == "$": self
.buyinCurrency
="USD"
173 elif mg
['CURRENCY'] == u
"€": self
.buyinCurrency
="EUR"
174 elif mg
['CURRENCY'] == "FPP": self
.buyinCurrency
="PSFP"
175 if self
.buyin
== 0: self
.buyinCurrency
="FREE"
176 self
.currency
= self
.buyinCurrency
178 m
= self
.re_Player
.finditer(self
.summaryText
)
181 #print "DEBUG: a.groupdict(): %s" % mg
183 rank
= int(mg
['RANK'])
189 if 'WINNINGS' in mg
and mg
['WINNINGS'] != None:
190 winnings
= int(100*Decimal(mg
['WINNINGS']))
192 if 'CUR' in mg
and mg
['CUR'] != None:
193 if mg
['CUR'] == "$": self
.currency
="USD"
194 elif mg
['CUR'] == u
"€": self
.currency
="EUR"
195 elif mg
['CUR'] == "FPP": self
.currency
="PSFP"
197 if 'STILLPLAYING' in mg
and mg
['STILLPLAYING'] != None:
198 #print "stillplaying"
202 if 'TICKET' and mg
['TICKET'] != None:
203 #print "Tournament Ticket Level %s" % mg['LEVEL']
205 '1' : '750', # Step 1 - $7.50 USD
206 '2' : '2750', # Step 2 - $27.00 USD
207 '3' : '8200', # Step 3 - $82.00 USD
208 '4' : '21500', # Step 4 - $215.00 USD
209 '5' : '70000', # Step 5 - $700.00 USD
210 '6' : '210000', # Step 6 - $2100.00 USD
212 winnings
= step_values
[mg
['LEVEL']]
214 #TODO: currency, ko/addon/rebuy count -> need examples!
215 #print "DEBUG: addPlayer(%s, %s, %s, %s, None, None, None)" %(rank, name, winnings, self.currency)
216 #print "DEBUG: self.buyin: %s self.fee %s" %(self.buyin, self.fee)
217 self
.addPlayer(rank
, name
, winnings
, self
.currency
, rebuyCount
, addOnCount
, koCount
)
221 #end class PokerStarsSummary