Coverage for BovadaSummary.py: 0%
117 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
4# Copyright 2008-2013 Chaz Littlejohn
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.
8#
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.
13#
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# import L10n
19# _ = L10n.get_translation()
21from decimal import Decimal
22import datetime
23import re
25from HandHistoryConverter import HandHistoryConverter, FpdbParseError
26from TourneySummary import TourneySummary
28import BovadaToFpdb
29import logging
31log = logging.getLogger("parser")
34class BovadaSummary(TourneySummary):
35 substitutions = {
36 "LEGAL_ISO": "USD", # legal ISO currency codes
37 "LS": "\$|", # legal currency symbols - Euro(cp1252, utf-8)
38 "PLYR": r"(?P<PNAME>.+?)",
39 "PLYR1": r"(?P<PNAME1>.+?)",
40 "CUR": "(\$|)",
41 "NUM": ".,\d",
42 }
43 codepage = ("utf8", "cp1252")
45 re_Identify = re.compile("(Ignition|Bovada|Bodog(\.eu|\sUK|\sCanada|88)?)\sHand")
46 re_AddOn = re.compile(r"^%(PLYR)s ?\[ME\] : Addon (?P<ADDON>[%(NUM)s]+)" % substitutions, re.MULTILINE)
47 re_Rebuyin = re.compile(r"%(PLYR)s ?\[ME\] : Rebuyin (?P<REBUY>[%(NUM)s]+)" % substitutions, re.MULTILINE)
48 re_Ranking = re.compile(
49 r"%(PLYR)s ?\[ME\] : Ranking (?P<RANK>[%(NUM)s]+)(\s+?%(PLYR1)s ?\[ME\] : Prize Cash \[(?P<WINNINGS>%(CUR)s[%(NUM)s]+)\])?"
50 % substitutions,
51 re.MULTILINE,
52 )
53 re_Stand = re.compile(r"%(PLYR)s ?\[ME\] : Stand" % substitutions, re.MULTILINE)
55 @staticmethod
56 def getSplitRe(self, head):
57 re_SplitTourneys = re.compile("PokerStars Tournament ")
58 return re_SplitTourneys
60 def parseSummary(self):
61 obj = getattr(BovadaToFpdb, "Bovada", None)
62 hhc = obj(self.config, in_path=self.in_path, sitename=None, autostart=False)
63 m = hhc.re_GameInfo.search(self.summaryText)
64 if m is None:
65 tmp = self.summaryText[0:200]
66 log.error(("BovadaSummary.parseSummary: '%s'") % tmp)
67 raise FpdbParseError
69 info = {}
70 info.update(m.groupdict())
71 m = hhc.re_Buyin.search(self.in_path)
72 if m:
73 info.update(m.groupdict())
75 if info["TOURNO"] is None:
76 tmp = self.summaryText[0:200]
77 log.error(("BovadaSummary.parseSummary: Text does not appear to be a tournament '%s'") % tmp)
78 raise FpdbParseError
79 else:
80 self.tourNo = info["TOURNO"]
81 if "LIMIT" in info:
82 if not info["LIMIT"]:
83 self.gametype["limitType"] = "nl"
84 else:
85 self.gametype["limitType"] = hhc.limits[info["LIMIT"]]
86 if "GAME" in info:
87 self.gametype["category"] = hhc.games[info["GAME"]][1]
89 if "CURRENCY" in info and info["CURRENCY"]:
90 self.buyinCurrency = hhc.currencies[info["CURRENCY"]]
91 self.currency = self.buyinCurrency
93 if "DATETIME" in info and info["CURRENCY"] is not None:
94 m1 = hhc.re_DateTime.finditer(info["DATETIME"])
95 datetimestr = "2000/01/01 00:00:00" # default used if time not found
96 for a in m1:
97 datetimestr = "%s/%s/%s %s:%s:%s" % (
98 a.group("Y"),
99 a.group("M"),
100 a.group("D"),
101 a.group("H"),
102 a.group("MIN"),
103 a.group("S"),
104 )
105 # tz = a.group('TZ') # just assume ET??
106 # print " tz = ", tz, " datetime =", datetimestr
107 self.startTime = datetime.datetime.strptime(
108 datetimestr, "%Y/%m/%d %H:%M:%S"
109 ) # also timezone at end, e.g. " ET"
110 self.startTime = HandHistoryConverter.changeTimezone(self.startTime, "ET", "UTC")
112 self.buyin = 0
113 self.fee = 0
114 self.prizepool = None
115 self.entries = None
117 if self.currency is None:
118 self.buyinCurrency = "FREE"
120 if "BUYIN" in info and info["BUYIN"] is not None:
121 if info["BIAMT"] is not None and info["BIRAKE"] is not None:
122 if info["BUYIN"].find("$") != -1:
123 self.buyinCurrency = "USD"
124 elif re.match("^[0-9+]*$", info["BUYIN"]):
125 self.buyinCurrency = "play"
126 else:
127 log.error(("BovadaSummary.parseSummary: Failed to detect currency"))
128 raise FpdbParseError
129 self.currency = self.buyinCurrency
131 info["BIAMT"] = hhc.clearMoneyString(info["BIAMT"].strip("$"))
133 if info["BIRAKE"]:
134 info["BIRAKE"] = hhc.clearMoneyString(info["BIRAKE"].strip("$"))
135 else:
136 info["BIRAKE"] = "0"
138 if info["TICKET"] is None:
139 self.buyin = int(100 * Decimal(info["BIAMT"]))
140 self.fee = int(100 * Decimal(info["BIRAKE"]))
141 else:
142 self.buyin = 0
143 self.fee = 0
145 if info["TOURNAME"] is not None:
146 tourneyNameFull = info["TOURNAME"] + " - " + info["BIAMT"] + "+" + info["BIRAKE"]
147 self.tourneyName = tourneyNameFull
149 if "TOURNAME" in info and "Rebuy" in info["TOURNAME"]:
150 self.isAddOn, self.isRebuy = True, True
151 self.rebuyCost = self.buyin
152 self.addOnCost = self.buyin
154 rebuys, addons, winnings = None, None, []
155 i = 0
156 m = self.re_Ranking.finditer(self.summaryText)
157 for a in m:
158 mg = a.groupdict()
159 winnings.append([int(mg["RANK"]), 0])
160 if mg["WINNINGS"] is not None:
161 if mg["WINNINGS"].find("$") != -1:
162 self.currency = "USD"
163 elif re.match("^[0-9+]*$", mg["WINNINGS"]):
164 self.currency = "play"
165 winnings[i][1] = int(100 * Decimal(self.clearMoneyString(mg["WINNINGS"])))
166 i += 1
168 m = self.re_Rebuyin.finditer(self.summaryText)
169 for a in m:
170 if rebuys is None:
171 rebuys = 0
172 rebuys += 1
174 m = self.re_AddOn.finditer(self.summaryText)
175 for a in m:
176 if addons is None:
177 addons = 0
178 addons += 1
180 i = 0
181 for win in winnings:
182 if len(win) > 1:
183 rankId = i + 1
184 else:
185 rankId = None
186 if i == 0:
187 self.addPlayer(win[0], "Hero", win[1], self.currency, rebuys, addons, rankId)
188 else:
189 self.addPlayer(win[0], "Hero", win[1], self.currency, 0, 0, rankId)
190 i += 1