From 8bd58e849ec0d152a4559fed8db98ed7b06eefb1 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Tue, 16 Dec 2008 17:14:37 +0000 Subject: [PATCH] some generality changes for FTP support --- pyfpdb/EverleafToFpdb.py | 33 ++++++++++++++------------------- pyfpdb/HandHistoryConverter.py | 6 +++++- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 9942105d..3aabaf6c 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -128,22 +128,19 @@ class Everleaf(HandHistoryConverter): #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"\*\* Dealing down cards \*\*(?P.+(?=\*\* Dealing Flop \*\*)|.+)" - r"(\*\* Dealing Flop \*\* \[ \S\S, \S\S, \S\S \](?P.+(?=\*\* Dealing Turn \*\*)|.+))?" - r"(\*\* Dealing Turn \*\* \[ \S\S \](?P.+(?=\*\* Dealing River \*\*)|.+))?" - r"(\*\* Dealing River \*\* \[ \S\S \](?P.+))?", hand.string,re.DOTALL) + r"(\*\* Dealing Flop \*\*(?P \[ \S\S, \S\S, \S\S \].+(?=\*\* Dealing Turn \*\*)|.+))?" + r"(\*\* Dealing Turn \*\*(?P \[ \S\S \].+(?=\*\* Dealing River \*\*)|.+))?" + r"(\*\* Dealing River \*\*(?P \[ \S\S \].+))?", hand.string,re.DOTALL) hand.addStreets(m) - def readCommunityCards(self, hand): - # currently regex in wrong place pls fix my brain's fried - re_board = re.compile('\*\* Dealing (?P.*) \*\* \[ (?P.*) \]') - m = re_board.finditer(hand.string) - for street in m: - #print street.groups() - re_card = re.compile('(?P[0-9tjqka][schd])') # look that's weird, hole cards have a capital rank but board cards are lower case? - cardsmatch = re_card.finditer(street.group('CARDS')) - hand.setCommunityCards(street.group('STREET'), [card.group('CARD') for card in cardsmatch]) + def readCommunityCards(self, hand, street): # street has been matched by markStreets, so exists in this hand + self.rexx.board_re = re.compile(r"\[ (?P.+) \]") + print hand.streets.group(street) + if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP) + m = self.rexx.board_re.search(hand.streets.group(street)) + hand.setCommunityCards(street, m.group('CARDS').split(', ')) def readBlinds(self, hand): try: @@ -184,27 +181,25 @@ class Everleaf(HandHistoryConverter): hand.addCheck( street, action.group('PNAME')) else: print "DEBUG: unimplemented readAction: %s %s" %(action.group('PNAME'),action.group('ATYPE'),) - #hand.actions[street] += [[action.group('PNAME'), action.group('ATYPE')]] - # TODO: Everleaf does not record uncalled bets. def readShowdownActions(self, hand): for shows in self.rexx.showdown_action_re.finditer(hand.string): cards = shows.group('CARDS') cards = set(cards.split(', ')) - #re_card = re.compile('(?P[0-9tjqka][schd])') # copied from earlier - #cards = set([card.group('CARD') for card in re_card.finditer(shows.group('CARDS'))]) hand.addShownCards(cards, shows.group('PNAME')) def readCollectPot(self,hand): + for m in self.rexx.collect_pot_re.finditer(hand.string): + hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT')) + + def readShownCards(self,hand): for m in self.rexx.collect_pot_re.finditer(hand.string): if m.group('CARDS') is not None: cards = m.group('CARDS') cards = set(cards.split(', ')) - #re_card = re.compile('(?P[0-9tjqka][schd])') # copied from earlier - #cards = set([hand.card(card.group('CARD')) for card in re_card.finditer(m.group('HAND'))]) hand.addShownCards(cards=None, player=m.group('PNAME'), holeandboard=cards) - hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT')) + if __name__ == "__main__": diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 858c18b3..b5d5909e 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -119,15 +119,18 @@ class HandHistoryConverter: self.markStreets(hand) self.readBlinds(hand) self.readHeroCards(hand) # want to generalise to draw games - self.readCommunityCards(hand) # read community cards + self.readShowdownActions(hand) # Read actions in street order for street in hand.streetList: # go through them in order if hand.streets.group(street) is not None: + self.readCommunityCards(hand, street) # read community cards self.readAction(hand, street) + self.readCollectPot(hand) + self.readShownCards(hand) # finalise it (total the pot) hand.totalPot() @@ -181,6 +184,7 @@ class HandHistoryConverter: def readHeroCards(self, hand): abstract def readAction(self, hand, street): abstract def readCollectPot(self, hand): abstract + def readShownCards(self, hand): abstract # Some sites don't report the rake. This will be called at the end of the hand after the pot total has been calculated # an inheriting class can calculate it for the specific site if need be.