From f5b52190ab523054290595156ef673e0fa9d85ac Mon Sep 17 00:00:00 2001 From: grindi Date: Wed, 3 Nov 2010 19:54:03 +0300 Subject: [PATCH 1/2] Make Party hhc to regonize non-english hh --- pyfpdb/PartyPokerToFpdb.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pyfpdb/PartyPokerToFpdb.py b/pyfpdb/PartyPokerToFpdb.py index a80810c7..cf29fb31 100755 --- a/pyfpdb/PartyPokerToFpdb.py +++ b/pyfpdb/PartyPokerToFpdb.py @@ -21,6 +21,7 @@ import sys from collections import defaultdict +from Configuration import LOCALE_ENCODING from Exceptions import FpdbParseError from HandHistoryConverter import * @@ -38,7 +39,7 @@ class FpdbParseError(FpdbParseError): class PartyPoker(HandHistoryConverter): sitename = "PartyPoker" - codepage = "cp1252" + codepage = "utf8" siteId = 9 filetype = "text" sym = {'USD': "\$", } @@ -52,7 +53,7 @@ class PartyPoker(HandHistoryConverter): (?P(Texas\ Hold\'em|Omaha)) \s*\-\s* (?P.+) - """, re.VERBOSE) + """, re.VERBOSE | re.UNICODE) re_GameInfoTrny = re.compile(""" (?P(NL|PL|))\s* (?P(Texas\ Hold\'em|Omaha))\s+ @@ -66,7 +67,7 @@ class PartyPoker(HandHistoryConverter): \) \s*\-\s* (?P.+) - """, re.VERBOSE) + """, re.VERBOSE | re.UNICODE) re_Hid = re.compile("^Game \#(?P\d+) starts.") re_PlayerInfo = re.compile(""" @@ -178,6 +179,10 @@ class PartyPoker(HandHistoryConverter): return self._gameType return self._gameType + @staticmethod + def decode_hand_text(handText): + return handText.encode("latin1").decode(LOCALE_ENCODING) + def determineGameType(self, handText): """inspect the handText and return the gametype dict @@ -185,6 +190,7 @@ class PartyPoker(HandHistoryConverter): {'limitType': xxx, 'base': xxx, 'category': xxx}""" info = {} + handText = self.decode_hand_text(handText) m = self._getGameType(handText) m_sb = self.re_ringSB.search(handText) m_bb = self.re_ringBB.search(handText) @@ -231,6 +237,10 @@ class PartyPoker(HandHistoryConverter): def readHandInfo(self, hand): + # we should redecode handtext here (as it imposible to it above) + # if you know more accurate way to do it - tell me + hand.handText = self.decode_hand_text(hand.handText) + info = {} try: info.update(self.re_Hid.search(hand.handText).groupdict()) @@ -279,10 +289,15 @@ class PartyPoker(HandHistoryConverter): #Saturday, July 25, 07:53:52 EDT 2009 #Thursday, July 30, 21:40:41 MSKS 2009 #Sunday, October 25, 13:39:07 MSK 2009 - m2 = re.search("\w+, (?P\w+) (?P\d+), (?P\d+):(?P\d+):(?P\d+) (?P[A-Z]+) (?P\d+)", info[key]) - # we cant use '%B' due to locale problems + m2 = re.search( + r"\w+,\s+(?P\w+)\s+(?P\d+),\s+(?P\d+):(?P\d+):(?P\d+)\s+(?P[A-Z]+)\s+(?P\d+)", + info[key], + re.UNICODE + ) months = ['January', 'February', 'March', 'April','May', 'June', 'July','August','September','October','November','December'] + if m2.group('M') not in months: + raise FpdbParseError("Only english hh is supported", hid=info["HID"]) month = months.index(m2.group('M')) + 1 datetimestr = "%s/%s/%s %s:%s:%s" % (m2.group('Y'), month,m2.group('D'),m2.group('H'),m2.group('MIN'),m2.group('S')) hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S") @@ -481,10 +496,8 @@ class PartyPoker(HandHistoryConverter): "Returns string to search in windows titles" if type=="tour": TableName = table_name.split(" ") - print 'party', 'getTableTitleRe', "%s.+Table\s#%s" % (TableName[0], table_number) return "%s.+Table\s#%s" % (TableName[0], table_number) else: - print 'party', 'getTableTitleRe', table_number return table_name def clearMoneyString(money): From 79bfc8587eeec4a65a3b4652701f4b2c891f638b Mon Sep 17 00:00:00 2001 From: grindi Date: Thu, 4 Nov 2010 12:57:39 +0300 Subject: [PATCH 2/2] Absolute hhc: fixes, cleanups, basic trny support --- pyfpdb/AbsoluteToFpdb.py | 174 ++++++++++++++++++++++++--------------- 1 file changed, 106 insertions(+), 68 deletions(-) diff --git a/pyfpdb/AbsoluteToFpdb.py b/pyfpdb/AbsoluteToFpdb.py index 6b57b1e4..b7fde682 100755 --- a/pyfpdb/AbsoluteToFpdb.py +++ b/pyfpdb/AbsoluteToFpdb.py @@ -2,12 +2,12 @@ # -*- coding: utf-8 -*- # # Copyright 2008-2010, Carl Gherardi -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -36,31 +36,55 @@ class Absolute(HandHistoryConverter): codepage = "cp1252" siteid = 8 HORSEHand = False - + # Static regexes re_SplitHands = re.compile(r"\n\n\n+") re_TailSplitHands = re.compile(r"(\n\n\n+)") -#Stage #1571362962: Holdem No Limit $0.02 - 2009-08-05 15:24:06 (ET) -#Table: TORONTO AVE (Real Money) Seat #6 is the dealer -#Seat 6 - FETS63 ($0.75 in chips) -#Board [10s 5d Kh Qh 8c] + #Stage #1571362962: Holdem No Limit $0.02 - 2009-08-05 15:24:06 (ET) + #Table: TORONTO AVE (Real Money) Seat #6 is the dealer + #Seat 6 - FETS63 ($0.75 in chips) + #Board [10s 5d Kh Qh 8c] + + re_GameInfo = re.compile( ur""" + ^Stage\s+\#C?(?P[0-9]+):?\s+ + (?:Tourney\ ID\ (?P\d+)\s+)? + (?PHoldem|Seven\ Card\ Hi\/L|HORSE)\s+ + (?P\(1\son\s1\)|Single\ Tournament|)\s* + (?PNo\ Limit|Pot\ Limit|Normal|)\s? + (?P\$|\s€|) + (?P[.0-9]+)/?(?:\$|\s€|)(?P[.0-9]+)? + \s+-\s+ + (?P\d\d\d\d-\d\d-\d\d\ \d\d:\d\d:\d\d)\s+ + (?: \( (?P[A-Z]+) \)\s+ )? + .*? + (Table:\ (?P.*?)\ \(Real\ Money\))? + """, re.MULTILINE|re.VERBOSE|re.DOTALL) + + re_HorseGameInfo = re.compile( + ur"^Game Type: (?PLimit) (?PHoldem)", + re.MULTILINE) + + re_HandInfo = re_GameInfo + + # on HORSE STUD games, the table name isn't in the hand info! + re_RingInfoFromFilename = re.compile(ur".*IHH([0-9]+) (?P
.*) -") + re_TrnyInfoFromFilename = re.compile( + ur".*IHH ([0-9]+) (?P.*) "\ + "ID (?P\d+) \((?P
\d+)\) .* "\ + "(?:\$|\s€|)(?P[0-9.]+)\s*\+\s*(?:\$|\s€|)(?P[0-9.]+)" + ) + + # TODO: that's not the right way to match for "dead" dealer is it? + re_Button = re.compile(ur"Seat #(?P
.*) \(Real Money\))?", re.MULTILINE) - re_TableFromFilename = re.compile(ur".*IHH([0-9]+) (?P
.*) -") # on HORSE STUD games, the table name isn't in the hand info! - re_Button = re.compile(ur"Seat #(?P