diff --git a/pyfpdb/BetfairToFpdb.py b/pyfpdb/BetfairToFpdb.py index 07ee2612..62db0311 100755 --- a/pyfpdb/BetfairToFpdb.py +++ b/pyfpdb/BetfairToFpdb.py @@ -44,8 +44,9 @@ class Betfair(HandHistoryConverter): siteId = 7 # Needs to match id entry in Sites database # Static regexes + #re_SplitHands = re.compile(r'\n\n+') # Betfair 1.0 version re_GameInfo = re.compile("^(?PNL|PL|) (?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+) (?P(Texas Hold\'em|Omaha Hi|Razz))", re.MULTILINE) - re_SplitHands = re.compile(r'\n\n+') + re_SplitHands = re.compile(r'End of hand .{2}-\d{7,9}-\d+ \*\*\*\*\*\n') re_HandInfo = re.compile("\*\*\*\*\* Betfair Poker Hand History for Game (?P[0-9]+) \*\*\*\*\*\n(?PNL|PL|) (?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+) (?P(Texas Hold\'em|Omaha Hi|Razz)) - (?P[a-zA-Z]+, [a-zA-Z]+ \d+, \d\d:\d\d:\d\d GMT \d\d\d\d)\nTable (?P[ a-zA-Z0-9]+) \d-max \(Real Money\)\nSeat (?P
[\' \w]+), (?P\d\d \w+ \d\d\d\d \d\d:\d\d (AM|PM))") - # SB BB HID TABLE DAY MON YEAR HR12 MIN AMPM + re_SplitHands = re.compile(r'End of hand .{2}-\d{7,9}-\d+ \*\*\*\*\*\n') + + # ***** History for hand R5-75443872-57 ***** + # Start hand: Wed Aug 18 19:29:10 GMT+0100 2010 + # Table: someplace [75443872] (LIMIT TEXAS_HOLDEM 0.50/1, Real money) + re_HandInfo = re.compile(u""" + \*\*\*\*\*\sHistory\sfor\shand\s(?P[-A-Z\d]+).* + Start\shand:\s(?P.*) + Table:\s(?P
[\'\w]+)\s\[\d+\]\s\( + ( + (?PNo\sLimit|Limit|LIMIT|Pot\sLimit)\s + (?PTEXAS_HOLDEM|RAZZ)\s + (?P[.0-9]+)/ + (?P[.0-9]+) + )? + """ % substitutions, re.MULTILINE|re.DOTALL|re.VERBOSE) + + # Wed Aug 18 19:45:30 GMT+0100 2010 + re_DateTime = re.compile(""" + [a-zA-Z]{3}\s + (?P[a-zA-Z]{3})\s + (?P[0-9]{2})\s + (?P[0-9]+):(?P[0-9]+):(?P[0-9]+)\sGMT + (?P[-+]\d+)\s + (?P[0-9]{4}) + """, re.MULTILINE|re.VERBOSE) # self.rexx.button_re = re.compile('#SUMMARY\nDealer: (?P.*)\n') #Seat 1: .Lucchess ($4.17 in chips) - re_PlayerInfo = re.compile(u'Seat (?P[0-9]+): (?P.*) \((\$(?P[.0-9]+) in chips)\)') - - #ANTES/BLINDS - #helander2222 posts blind ($0.25), lopllopl posts blind ($0.50). - re_PostSB = re.compile('(?P.*) posts blind \(\$?(?P[.0-9]+)\), ') - re_PostBB = re.compile('\), (?P.*) posts blind \(\$?(?P[.0-9]+)\).') - re_PostBoth = re.compile('.*\n(?P.*): posts small \& big blinds \[\$? (?P[.0-9]+)') - re_HeroCards = re.compile('.*\nDealt\sto\s(?P.*)\s\[ (?P.*) \]') - - #lopllopl checks, Eurolll checks, .Lucchess checks. - re_Action = re.compile('(, )?(?P.*?)(?P bets| checks| raises| calls| folds)( \$(?P\d*\.?\d*))?( and is all-in)?') - re_Board = re.compile(r"\[board cards (?P.+) \]") - - #Uchilka shows [ KC,JD ] - re_ShowdownAction = re.compile('(?P.*) shows \[ (?P.+) \]') - - # TODO: read SUMMARY correctly for collected pot stuff. - #Uchilka, bets $11.75, collects $23.04, net $11.29 - re_CollectPot = re.compile('(?P.*), bets.+, collects \$(?P\d*\.?\d*), net.* ') - re_sitsOut = re.compile('(?P.*) sits out') + re_PlayerInfo = re.compile(u'Seat (?P[0-9]+): (?P.*) \((?P[.0-9]+) \)') + + def compilePlayerRegexs(self, hand): + players = set([player[1] for player in hand.players]) + if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' + # we need to recompile the player regexs. +# TODO: should probably rename re_HeroCards and corresponding method, +# since they are used to find all cards on lines starting with "Dealt to:" +# They still identify the hero. + + #ANTES/BLINDS + #helander2222 posts blind ($0.25), lopllopl posts blind ($0.50). + player_re = "(?P" + "|".join(map(re.escape, players)) + ")" + subst = {'PLYR': player_re, 'CUR': self.sym[hand.gametype['currency']]} + re_PostSB = re.compile('(?P.*) posts blind \(\$?(?P[.0-9]+)\), ') + re_PostBB = re.compile('\), (?P.*) posts blind \(\$?(?P[.0-9]+)\).') + re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + re_PostBoth = re.compile('.*\n(?P.*): posts small \& big blinds \[\$? (?P[.0-9]+)') + re_HeroCards = re.compile('.*\nDealt\sto\s(?P.*)\s\[ (?P.*) \]') + + #lopllopl checks, Eurolll checks, .Lucchess checks. + re_Action = re.compile('(, )?(?P.*?)(?P bets| checks| raises| calls| folds)( \$(?P\d*\.?\d*))?( and is all-in)?') + re_Board = re.compile(r"\[board cards (?P.+) \]") + + #Uchilka shows [ KC,JD ] + re_ShowdownAction = re.compile('(?P.*) shows \[ (?P.+) \]') + + # TODO: read SUMMARY correctly for collected pot stuff. + #Uchilka, bets $11.75, collects $23.04, net $11.29 + re_CollectPot = re.compile('(?P.*), bets.+, collects \$(?P\d*\.?\d*), net.* ') + re_sitsOut = re.compile('(?P.*) sits out') def readSupportedGames(self): - pass + return [ + ["ring", "hold", "fl"], + ["ring", "hold", "nl"], + ] def determineGameType(self, handText): - # Cheating with this regex, only support nlhe at the moment - gametype = ["ring", "hold", "nl"] + # Inspect the handText and return the gametype dict + # gametype dict is: {'limitType': xxx, 'base': xxx, 'category': xxx} + info = {} m = self.re_HandInfo.search(handText) if not m: @@ -90,36 +146,54 @@ class OnGame(HandHistoryConverter): log.error(_("determineGameType: Raising FpdbParseError")) raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp) - gametype = gametype + [m.group('SB')] - gametype = gametype + [m.group('BB')] - - return gametype + mg = m.groupdict() + + info['type'] = 'ring' + info['currency'] = 'USD' + + if 'LIMIT' in mg: + info['limitType'] = self.limits[mg['LIMIT']] + if 'GAME' in mg: + (info['base'], info['category']) = self.games[mg['GAME']] + if 'SB' in mg: + info['sb'] = mg['SB'] + if 'BB' in mg: + info['bb'] = mg['BB'] + + return info def readHandInfo(self, hand): - m = self.re_HandInfo.search(hand.string) - hand.handid = m.group('HID') - hand.tablename = m.group('TABLE') - #hand.buttonpos = self.rexx.button_re.search(hand.string).group('BUTTONPNAME') -# These work, but the info is already in the Hand class - should be used for tourneys though. -# m.group('SB') -# m.group('BB') -# m.group('GAMETYPE') + info = {} + m = self.re_HandInfo.search(hand.handText) -# Believe Everleaf time is GMT/UTC, no transation necessary -# Stars format (Nov 10 2008): 2008/11/07 12:38:49 CET [2008/11/07 7:38:49 ET] -# or : 2008/11/07 12:38:49 ET -# Not getting it in my HH files yet, so using -# 2008/11/10 3:58:52 ET -#TODO: Do conversion from GMT to ET -#TODO: Need some date functions to convert to different timezones (Date::Manip for perl rocked for this) - - hand.startTime = time.strptime(m.group('DATETIME'), "%d %b %Y %I:%M %p") - #hand.starttime = "%d/%02d/%02d %d:%02d:%02d ET" %(int(m.group('YEAR')), int(m.group('MON')), int(m.group('DAY')), - #int(m.group('HR')), int(m.group('MIN')), int(m.group('SEC'))) + if m: + info.update(m.groupdict()) + + log.debug("readHandInfo: %s" % info) + for key in info: + if key == 'DATETIME': + #'Wed Aug 18 19:45:30 GMT+0100 2010 + # %a %b %d %H:%M:%S %z %Y + #hand.startTime = time.strptime(m.group('DATETIME'), "%a %b %d %H:%M:%S GMT%z %Y") + # Stupid library doesn't seem to support %z (http://docs.python.org/library/time.html?highlight=strptime#time.strptime) + # So we need to re-interpret te string to be useful + m1 = self.re_DateTime.finditer(info[key]) + for a in m1: + datetimestr = "%s %s %s %s:%s:%s" % (a.group('M'),a.group('D'), a.group('Y'), a.group('H'),a.group('MIN'),a.group('S')) + hand.startTime = time.strptime(datetimestr, "%b %d %Y %H:%M:%S") + # TODO: Manually adjust time against OFFSET + if key == 'HID': + hand.handid = info[key] + if key == 'TABLE': + hand.tablename = info[key] + + # TODO: These + hand.buttonpos = 1 + hand.maxseats = 10 + hand.mixed = None def readPlayerStacks(self, hand): - m = self.re_PlayerInf.finditer(hand.string) - players = [] + m = self.re_PlayerInfo.finditer(hand.handText) for a in m: hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH')) @@ -128,13 +202,27 @@ class OnGame(HandHistoryConverter): # This re fails if, say, river is missing; then we don't get the ** that starts the river. #m = re.search('(\*\* Dealing down cards \*\*\n)(?P.*?\n\*\*)?( Dealing Flop \*\* \[ (?P\S\S), (?P\S\S), (?P\S\S) \])?(?P.*?\*\*)?( Dealing Turn \*\* \[ (?P\S\S) \])?(?P.*?\*\*)?( Dealing River \*\* \[ (?P\S\S) \])?(?P.*)', hand.string,re.DOTALL) - m = re.search(r"PRE-FLOP(?P.+(?=FLOP)|.+(?=SHOWDOWN))" - r"(FLOP (?P\[board cards .+ \].+(?=TURN)|.+(?=SHOWDOWN)))?" - r"(TURN (?P\[board cards .+ \].+(?=RIVER)|.+(?=SHOWDOWN)))?" - r"(RIVER (?P\[board cards .+ \].+(?=SHOWDOWN)))?", hand.string,re.DOTALL) + #if hand.gametype['base'] in ("hold"): + #elif hand.gametype['base'] in ("stud"): + #elif hand.gametype['base'] in ("draw"): + # only holdem so far: + m = re.search(r"pocket cards(?P.+(?=flop)|.+(?=Summary))" + r"(flop (?P\[\S\S, \S\S, \S\S\].+(?=turn)|.+(?=Summary)))?" + r"(turn (?P\[\S\S, \S\S, \S\S\, \S\S\].+(?=river)|.+(?=Summary)))?" + r"(river (?P\[\S\S, \S\S, \S\S\, \S\S, \S\S\].+(?=Summary)))?", hand.handText, re.DOTALL) hand.addStreets(m) - + + #Needs to return a list in the format + # ['player1name', 'player2name', ...] where player1name is the sb and player2name is bb, + # addtional players are assumed to post a bb oop + + def readButton(self, hand): + m = self.re_Button.search(hand.handText) + if m: + hand.buttonpos = int(m.group('BUTTON')) + else: + log.info(_('readButton: not found')) def readCommunityCards(self, hand, street): print hand.streets.group(street) @@ -144,17 +232,30 @@ class OnGame(HandHistoryConverter): def readBlinds(self, hand): try: - m = self.re_PostSB.search(hand.string) + m = self.re_PostSB.search(hand.handText) hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB')) except: # no small blind hand.addBlind(None, None, None) - for a in self.re_PostBB.finditer(hand.string): + for a in self.re_PostBB.finditer(hand.handText): hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB')) - for a in self.re_PostBoth.finditer(hand.string): + for a in self.re_PostBoth.finditer(hand.handText): hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB')) + def readAntes(self, hand): + log.debug(_("reading antes")) + m = self.re_Antes.finditer(hand.handText) + for player in m: + #~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE'))) + hand.addAnte(player.group('PNAME'), player.group('ANTE')) + + def readBringIn(self, hand): + m = self.re_BringIn.search(hand.handText,re.DOTALL) + if m: + #~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN'))) + hand.addBringIn(m.group('PNAME'), m.group('BRINGIN')) + def readHeroCards(self, hand): - m = self.re_HeroCards.search(hand.string) + m = self.re_HeroCards.search(hand.handText) if(m == None): #Not involved in hand hand.involved = False @@ -185,13 +286,13 @@ class OnGame(HandHistoryConverter): # TODO: Everleaf does not record uncalled bets. def readShowdownActions(self, hand): - for shows in self.re_ShowdownAction.finditer(hand.string): + for shows in self.re_ShowdownAction.finditer(hand.handText): cards = shows.group('CARDS') cards = set(cards.split(',')) hand.addShownCards(cards, shows.group('PNAME')) def readCollectPot(self,hand): - for m in self.re_CollectPot.finditer(hand.string): + for m in self.re_CollectPot.finditer(hand.handText): hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT')) def readShownCards(self,hand): diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index d3004bdb..c97c5893 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -1093,6 +1093,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an self.status_bar = None self.quitting = False + self.visible = False self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) @@ -1130,6 +1131,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an self.tab_main_help(None, None) self.window.show() + self.visible = True # Flip on self.load_profile(create_db = True) if not options.errorsToConsole: @@ -1165,21 +1167,31 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an self.window.connect('window-state-event', self.window_state_event_cb) sys.stderr.write(_("fpdb starting ...")) + + def __iconify(self): + self.visible = False + self.window.set_skip_taskbar_hint(True) + self.window.set_skip_pager_hind(True) + + def __deiconify(self): + self.visible = True + self.window.set_skip_taskbar_hint(False) + self.window.set_skip_pager_hind(False) + def window_state_event_cb(self, window, event): + # Deal with iconification first if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: - # -20 = GWL_EXSTYLE can't find it in the pywin32 libs - #bits = win32api.GetWindowLong(self.window.window.handle, -20) - #bits = bits ^ (win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_APPWINDOW) - - #win32api.SetWindowLong(self.window.window.handle, -20, bits) - if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED: - self.window.hide() - self.window.set_skip_taskbar_hint(True) - self.window.set_skip_pager_hint(True) + self.__iconify() else: - self.window.set_skip_taskbar_hint(False) - self.window.set_skip_pager_hint(False) + self.__deiconify() + if not event.new_window_state & gtk.gdk.WINDOW_STATE_WITHDRAWN: + return True + # And then the tray icon click + if event.new_window_state & gtk.gdk.WINDOW_STATE_WITHDRAWN: + self.__iconify() + else: + self.__deiconify() # Tell GTK not to propagate this signal any further return True @@ -1197,11 +1209,9 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an def statusicon_activate(self, widget, data = None): # Let's allow the tray icon to toggle window visibility, the way # most other apps work - shown = self.window.get_property('visible') - if shown: + if self.visible: self.window.hide() else: - self.window.show() self.window.present() def info_box(self, str1, str2):