Carbon Poker offers a 5 card stud game that wasn't listed here. It's not available...
[fpdb-dooglus.git] / pyfpdb / PokerStarsSummary.py
blob8b3180947c41c27920d4484b4fa6f22c57531798
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2011 Steffen Schaumburg
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"""
20 import L10n
21 _ = L10n.get_translation()
23 from decimal_wrapper import Decimal
24 import datetime
26 from Exceptions import FpdbParseError
27 from HandHistoryConverter import *
28 import PokerStarsToFpdb
29 from TourneySummary import *
31 class PokerStarsSummary(TourneySummary):
32 limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
33 games = { # base, category
34 "Hold'em" : ('hold','holdem'),
35 'Omaha' : ('hold','omahahi'),
36 'Omaha Hi/Lo' : ('hold','omahahilo'),
37 'Razz' : ('stud','razz'),
38 'RAZZ' : ('stud','razz'),
39 '7 Card Stud' : ('stud','studhi'),
40 '7 Card Stud Hi/Lo' : ('stud','studhilo'),
41 'Badugi' : ('draw','badugi'),
42 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
43 '5 Card Draw' : ('draw','fivedraw')
46 substitutions = {
47 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
48 'LS' : u"\$|\xe2\x82\xac|\u20AC|" # legal currency symbols - Euro(cp1252, utf-8)
51 re_SplitTourneys = re.compile("PokerStars Tournament ")
53 re_TourNo = re.compile("\#(?P<TOURNO>[0-9]+),")
55 re_TourneyInfo = re.compile(u"""
56 \#(?P<TOURNO>[0-9]+),\s
57 (?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\s
58 (?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+
59 (?P<DESC>[ a-zA-Z]+\s+)?
60 (Buy-In:\s[%(LS)s](?P<BUYIN>[.0-9]+)(\/[%(LS)s](?P<FEE>[.0-9]+))?(?P<CUR>\s(%(LEGAL_ISO)s))?\s+)?
61 (?P<ENTRIES>[0-9]+)\splayers\s+
62 ([%(LS)s]?(?P<ADDED>[.\d]+)\sadded\sto\sthe\sprize\spool\sby\sPokerStars\.com\s+)?
63 (Total\sPrize\sPool:\s[%(LS)s]?(?P<PRIZEPOOL>[.0-9]+)(\s(%(LEGAL_ISO)s))?\s+)?
64 (Target\sTournament\s.*)?
65 Tournament\sstarted\s+(-\s)?
66 (?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
67 """ % substitutions ,re.VERBOSE|re.MULTILINE|re.DOTALL)
69 re_Currency = re.compile(u"""(?P<CURRENCY>[%(LS)s]|FPP)""" % substitutions)
71 re_Player = re.compile(u"""(?P<RANK>[0-9]+):\s(?P<NAME>.*)\s\(.*\),(\s)?([%(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)
73 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]+)")
75 codepage = ["utf-8"]
77 def parseSummary(self):
78 m = self.re_TourneyInfo.search(self.summaryText)
79 if m == None:
80 tmp = self.summaryText[0:200]
81 log.error("parseSummary: " + _("Unable to recognise Tourney Info: '%s'") % tmp)
82 log.error("parseSummary: " + _("Raising FpdbParseError"))
83 raise FpdbParseError(_("Unable to recognise Tourney Info: '%s'") % tmp)
85 #print "DEBUG: m.groupdict(): %s" % m.groupdict()
87 mg = m.groupdict()
88 if 'TOURNO' in mg: self.tourNo = mg['TOURNO']
89 if 'LIMIT' in mg: self.gametype['limitType'] = self.limits[mg['LIMIT']]
90 if 'GAME' in mg: self.gametype['category'] = self.games[mg['GAME']][1]
91 if mg['BUYIN'] != None:
92 self.buyin = int(100*Decimal(mg['BUYIN']))
93 if mg['FEE'] != None:
94 self.fee = int(100*Decimal(mg['FEE']))
95 if 'PRIZEPOOL' in mg: self.prizepool = mg['PRIZEPOOL']
96 if 'ENTRIES' in mg: self.entries = mg['ENTRIES']
98 datetimestr = "%s/%s/%s %s:%s:%s" % (mg['Y'], mg['M'], mg['D'], mg['H'], mg['MIN'], mg['S'])
99 self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
101 if 'TZ' in mg:
102 self.startTime = HandHistoryConverter.changeTimezone(self.startTime, mg['TZ'], "UTC")
105 m = self.re_Currency.search(self.summaryText)
106 if m == None:
107 log.error("parseSummary: " + _("Unable to locate currency"))
108 log.error("parseSummary: " + _("Raising FpdbParseError"))
109 raise FpdbParseError(_("Unable to locate currency"))
110 #print "DEBUG: m.groupdict(): %s" % m.groupdict()
112 mg = m.groupdict()
113 if mg['CURRENCY'] == "$": self.currency = "USD"
114 elif mg['CURRENCY'] == u"€": self.currency="EUR"
115 elif mg['CURRENCY'] == "FPP": self.currency="PSFP"
117 m = self.re_Player.finditer(self.summaryText)
118 for a in m:
119 mg = a.groupdict()
120 #print "DEBUG: a.groupdict(): %s" % mg
121 name = mg['NAME']
122 rank = mg['RANK']
123 winnings = 0
125 if 'WINNINGS' in mg and mg['WINNINGS'] != None:
126 winnings = int(100*Decimal(mg['WINNINGS']))
128 if 'STILLPLAYING' in mg and mg['STILLPLAYING'] != None:
129 #print "stillplaying"
130 rank=None
131 winnings=None
133 if 'TICKET' and mg['TICKET'] != None:
134 #print "Tournament Ticket Level %s" % mg['LEVEL']
135 step_values = {
136 '1' : '750', # Step 1 - $7.50 USD
137 '2' : '2750', # Step 2 - $27.00 USD
138 '3' : '8200', # Step 3 - $82.00 USD
139 '4' : '21500', # Step 4 - $215.00 USD
140 '5' : '70000', # Step 5 - $700.00 USD
141 '6' : '210000', # Step 6 - $2100.00 USD
143 winnings = step_values[mg['LEVEL']]
145 #TODO: currency, ko/addon/rebuy count -> need examples!
146 #print "DEBUG: addPlayer(%s, %s, %s, %s, None, None, None)" %(rank, name, winnings, self.currency)
147 #print "DEBUG: self.buyin: %s self.fee %s" %(self.buyin, self.fee)
148 self.addPlayer(rank, name, winnings, self.currency, None, None, None)
150 #print self
152 #end class PokerStarsSummary