Make Party hhc to regonize non-english hh

This commit is contained in:
grindi 2010-11-03 19:54:03 +03:00
parent 779befae18
commit f5b52190ab

View File

@ -21,6 +21,7 @@
import sys import sys
from collections import defaultdict from collections import defaultdict
from Configuration import LOCALE_ENCODING
from Exceptions import FpdbParseError from Exceptions import FpdbParseError
from HandHistoryConverter import * from HandHistoryConverter import *
@ -38,7 +39,7 @@ class FpdbParseError(FpdbParseError):
class PartyPoker(HandHistoryConverter): class PartyPoker(HandHistoryConverter):
sitename = "PartyPoker" sitename = "PartyPoker"
codepage = "cp1252" codepage = "utf8"
siteId = 9 siteId = 9
filetype = "text" filetype = "text"
sym = {'USD': "\$", } sym = {'USD': "\$", }
@ -52,7 +53,7 @@ class PartyPoker(HandHistoryConverter):
(?P<GAME>(Texas\ Hold\'em|Omaha)) (?P<GAME>(Texas\ Hold\'em|Omaha))
\s*\-\s* \s*\-\s*
(?P<DATETIME>.+) (?P<DATETIME>.+)
""", re.VERBOSE) """, re.VERBOSE | re.UNICODE)
re_GameInfoTrny = re.compile(""" re_GameInfoTrny = re.compile("""
(?P<LIMIT>(NL|PL|))\s* (?P<LIMIT>(NL|PL|))\s*
(?P<GAME>(Texas\ Hold\'em|Omaha))\s+ (?P<GAME>(Texas\ Hold\'em|Omaha))\s+
@ -66,7 +67,7 @@ class PartyPoker(HandHistoryConverter):
\) \)
\s*\-\s* \s*\-\s*
(?P<DATETIME>.+) (?P<DATETIME>.+)
""", re.VERBOSE) """, re.VERBOSE | re.UNICODE)
re_Hid = re.compile("^Game \#(?P<HID>\d+) starts.") re_Hid = re.compile("^Game \#(?P<HID>\d+) starts.")
re_PlayerInfo = re.compile(""" re_PlayerInfo = re.compile("""
@ -178,6 +179,10 @@ class PartyPoker(HandHistoryConverter):
return self._gameType return self._gameType
return self._gameType return self._gameType
@staticmethod
def decode_hand_text(handText):
return handText.encode("latin1").decode(LOCALE_ENCODING)
def determineGameType(self, handText): def determineGameType(self, handText):
"""inspect the handText and return the gametype dict """inspect the handText and return the gametype dict
@ -185,6 +190,7 @@ class PartyPoker(HandHistoryConverter):
{'limitType': xxx, 'base': xxx, 'category': xxx}""" {'limitType': xxx, 'base': xxx, 'category': xxx}"""
info = {} info = {}
handText = self.decode_hand_text(handText)
m = self._getGameType(handText) m = self._getGameType(handText)
m_sb = self.re_ringSB.search(handText) m_sb = self.re_ringSB.search(handText)
m_bb = self.re_ringBB.search(handText) m_bb = self.re_ringBB.search(handText)
@ -231,6 +237,10 @@ class PartyPoker(HandHistoryConverter):
def readHandInfo(self, hand): 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 = {} info = {}
try: try:
info.update(self.re_Hid.search(hand.handText).groupdict()) info.update(self.re_Hid.search(hand.handText).groupdict())
@ -279,10 +289,15 @@ class PartyPoker(HandHistoryConverter):
#Saturday, July 25, 07:53:52 EDT 2009 #Saturday, July 25, 07:53:52 EDT 2009
#Thursday, July 30, 21:40:41 MSKS 2009 #Thursday, July 30, 21:40:41 MSKS 2009
#Sunday, October 25, 13:39:07 MSK 2009 #Sunday, October 25, 13:39:07 MSK 2009
m2 = re.search("\w+, (?P<M>\w+) (?P<D>\d+), (?P<H>\d+):(?P<MIN>\d+):(?P<S>\d+) (?P<TZ>[A-Z]+) (?P<Y>\d+)", info[key]) m2 = re.search(
# we cant use '%B' due to locale problems r"\w+,\s+(?P<M>\w+)\s+(?P<D>\d+),\s+(?P<H>\d+):(?P<MIN>\d+):(?P<S>\d+)\s+(?P<TZ>[A-Z]+)\s+(?P<Y>\d+)",
info[key],
re.UNICODE
)
months = ['January', 'February', 'March', 'April','May', 'June', months = ['January', 'February', 'March', 'April','May', 'June',
'July','August','September','October','November','December'] '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 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')) 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") 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" "Returns string to search in windows titles"
if type=="tour": if type=="tour":
TableName = table_name.split(" ") TableName = table_name.split(" ")
print 'party', 'getTableTitleRe', "%s.+Table\s#%s" % (TableName[0], table_number)
return "%s.+Table\s#%s" % (TableName[0], table_number) return "%s.+Table\s#%s" % (TableName[0], table_number)
else: else:
print 'party', 'getTableTitleRe', table_number
return table_name return table_name
def clearMoneyString(money): def clearMoneyString(money):