Coverage for BovadaSummary.py: 0%

114 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 18:50 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3 

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. 

17 

18#import L10n 

19#_ = L10n.get_translation() 

20 

21from decimal_wrapper import Decimal 

22import datetime 

23 

24from Exceptions import FpdbParseError 

25from HandHistoryConverter import * 

26from TourneySummary import * 

27import BovadaToFpdb 

28 

29class BovadaSummary(TourneySummary): 

30 

31 substitutions = { 

32 'LEGAL_ISO' : "USD", # legal ISO currency codes 

33 'LS' : u"\$|", # legal currency symbols - Euro(cp1252, utf-8) 

34 'PLYR': r'(?P<PNAME>.+?)', 

35 'PLYR1': r'(?P<PNAME1>.+?)', 

36 'CUR': u"(\$|)", 

37 'NUM' :u".,\d", 

38 } 

39 codepage = ("utf8", "cp1252") 

40 

41 re_Identify = re.compile(u'(Ignition|Bovada|Bodog(\.eu|\sUK|\sCanada|88)?)\sHand') 

42 re_AddOn = re.compile(r"^%(PLYR)s ?\[ME\] : Addon (?P<ADDON>[%(NUM)s]+)" % substitutions, re.MULTILINE) 

43 re_Rebuyin = re.compile(r"%(PLYR)s ?\[ME\] : Rebuyin (?P<REBUY>[%(NUM)s]+)" % substitutions, re.MULTILINE) 

44 re_Ranking = re.compile(r"%(PLYR)s ?\[ME\] : Ranking (?P<RANK>[%(NUM)s]+)(\s+?%(PLYR1)s ?\[ME\] : Prize Cash \[(?P<WINNINGS>%(CUR)s[%(NUM)s]+)\])?" % substitutions, re.MULTILINE) 

45 re_Stand = re.compile(r"%(PLYR)s ?\[ME\] : Stand" % substitutions, re.MULTILINE) 

46 

47 @staticmethod 

48 def getSplitRe(self, head): 

49 re_SplitTourneys = re.compile("PokerStars Tournament ") 

50 return re_SplitTourneys 

51 

52 def parseSummary(self): 

53 obj = getattr(BovadaToFpdb, "Bovada", None) 

54 hhc = obj(self.config, in_path = self.in_path, sitename = None, autostart = False) 

55 m = hhc.re_GameInfo.search(self.summaryText) 

56 if m == None: 

57 tmp = self.summaryText[0:200] 

58 log.error(("BovadaSummary.parseSummary: '%s'") % tmp) 

59 raise FpdbParseError 

60 

61 info = {} 

62 info.update(m.groupdict()) 

63 m = hhc.re_Buyin.search(self.in_path) 

64 if m: info.update(m.groupdict()) 

65 

66 if info['TOURNO'] is None: 

67 tmp = self.summaryText[0:200] 

68 log.error(("BovadaSummary.parseSummary: Text does not appear to be a tournament '%s'") % tmp) 

69 raise FpdbParseError 

70 else: 

71 self.tourNo = info['TOURNO'] 

72 if 'LIMIT' in info: 

73 if not info['LIMIT']: 

74 self.gametype['limitType'] = 'nl' 

75 else: 

76 self.gametype['limitType'] = hhc.limits[info['LIMIT']] 

77 if 'GAME' in info: 

78 self.gametype['category'] = hhc.games[info['GAME']][1] 

79 

80 if 'CURRENCY' in info and info['CURRENCY']: 

81 self.buyinCurrency = hhc.currencies[info['CURRENCY']] 

82 self.currency = self.buyinCurrency 

83 

84 if 'DATETIME' in info and info['CURRENCY'] is not None: 

85 m1 = hhc.re_DateTime.finditer(info['DATETIME']) 

86 datetimestr = "2000/01/01 00:00:00" # default used if time not found 

87 for a in m1: 

88 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')) 

89 #tz = a.group('TZ') # just assume ET?? 

90 #print " tz = ", tz, " datetime =", datetimestr 

91 self.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET" 

92 self.startTime = HandHistoryConverter.changeTimezone(self.startTime, "ET", "UTC") 

93 

94 self.buyin = 0 

95 self.fee = 0 

96 self.prizepool = None 

97 self.entries = None 

98 

99 if self.currency is None: 

100 self.buyinCurrency = "FREE" 

101 

102 if 'BUYIN' in info and info['BUYIN'] is not None: 

103 if info['BIAMT'] is not None and info['BIRAKE'] is not None: 

104 if info['BUYIN'].find("$")!=-1: 

105 self.buyinCurrency="USD" 

106 elif re.match("^[0-9+]*$", info['BUYIN']): 

107 self.buyinCurrency="play" 

108 else: 

109 log.error(("BovadaSummary.parseSummary: Failed to detect currency")) 

110 raise FpdbParseError 

111 self.currency = self.buyinCurrency 

112 

113 info['BIAMT'] = hhc.clearMoneyString(info['BIAMT'].strip(u'$')) 

114 

115 if info['BIRAKE']: 

116 info['BIRAKE'] = hhc.clearMoneyString(info['BIRAKE'].strip(u'$')) 

117 else: 

118 info['BIRAKE'] = '0' 

119 

120 if info['TICKET'] == None: 

121 self.buyin = int(100*Decimal(info['BIAMT'])) 

122 self.fee = int(100*Decimal(info['BIRAKE'])) 

123 else: 

124 self.buyin = 0 

125 self.fee = 0 

126 

127 if info['TOURNAME'] is not None: 

128 tourneyNameFull = info['TOURNAME'] + ' - ' + info['BIAMT'] + '+' + info['BIRAKE'] 

129 self.tourneyName = tourneyNameFull 

130 

131 if 'TOURNAME' in info and 'Rebuy' in info['TOURNAME']: 

132 self.isAddOn, self.isRebuy = True, True 

133 self.rebuyCost = self.buyin 

134 self.addOnCost = self.buyin 

135 

136 rebuys, addons, winnings = None, None, [] 

137 i = 0 

138 m = self.re_Ranking.finditer(self.summaryText) 

139 for a in m: 

140 mg = a.groupdict() 

141 winnings.append([int(mg['RANK']), 0]) 

142 if mg['WINNINGS'] is not None: 

143 if mg['WINNINGS'].find("$")!=-1: 

144 self.currency="USD" 

145 elif re.match("^[0-9+]*$", mg['WINNINGS']): 

146 self.currency="play" 

147 winnings[i][1] = int(100*Decimal(self.clearMoneyString(mg['WINNINGS']))) 

148 i+=1 

149 

150 m = self.re_Rebuyin.finditer(self.summaryText) 

151 for a in m: 

152 if rebuys == None: 

153 rebuys = 0 

154 rebuys += 1 

155 

156 m = self.re_AddOn.finditer(self.summaryText) 

157 for a in m: 

158 if addons == None: 

159 addons = 0 

160 addons += 1 

161 

162 i = 0 

163 for win in winnings: 

164 if len(win)>1: 

165 rankId = (i+1) 

166 else: 

167 rankId = None 

168 if i == 0: 

169 self.addPlayer(win[0], 'Hero', win[1], self.currency, rebuys, addons, rankId) 

170 else: 

171 self.addPlayer(win[0], 'Hero', win[1], self.currency, 0, 0, rankId) 

172 i+=1 

173