Parse another PokerStars datetime.
Make tail work: -log instead of print inode # change detected, -make sure splitter regexes have groups around them -fix a bug -increase buffering size to something >> a single hand Conflicts: pyfpdb/HandHistoryConverter.py
This commit is contained in:
parent
ff3409abf3
commit
aca5dc9ed0
|
@ -27,7 +27,7 @@ from HandHistoryConverter import *
|
||||||
class Everleaf(HandHistoryConverter):
|
class Everleaf(HandHistoryConverter):
|
||||||
|
|
||||||
# Static regexes
|
# Static regexes
|
||||||
re_SplitHands = re.compile(r"\n\n+")
|
re_SplitHands = re.compile(r"(\n\n\n+)")
|
||||||
re_GameInfo = re.compile(ur"^(Blinds )?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/(?:\$| €)?(?P<BB>[.0-9]+) (?P<LIMIT>NL|PL|) ?(?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
|
re_GameInfo = re.compile(ur"^(Blinds )?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/(?:\$| €)?(?P<BB>[.0-9]+) (?P<LIMIT>NL|PL|) ?(?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
|
||||||
#re.compile(ur"^(Blinds )?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/(?:\$| €)?(?P<BB>[.0-9]+) (?P<LIMIT>NL|PL|) (?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
|
#re.compile(ur"^(Blinds )?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/(?:\$| €)?(?P<BB>[.0-9]+) (?P<LIMIT>NL|PL|) (?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
|
||||||
re_HandInfo = re.compile(ur".*#(?P<HID>[0-9]+)\n.*\n(Blinds )?(?:\$| €|)(?P<SB>[.0-9]+)/(?:\$| €|)(?P<BB>[.0-9]+) (?P<GAMETYPE>.*) - (?P<DATETIME>\d\d\d\d/\d\d/\d\d - \d\d:\d\d:\d\d)\nTable (?P<TABLE>.+$)", re.MULTILINE)
|
re_HandInfo = re.compile(ur".*#(?P<HID>[0-9]+)\n.*\n(Blinds )?(?:\$| €|)(?P<SB>[.0-9]+)/(?:\$| €|)(?P<BB>[.0-9]+) (?P<GAMETYPE>.*) - (?P<DATETIME>\d\d\d\d/\d\d/\d\d - \d\d:\d\d:\d\d)\nTable (?P<TABLE>.+$)", re.MULTILINE)
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Fulltilt(HandHistoryConverter):
|
||||||
|
|
||||||
# Static regexes
|
# Static regexes
|
||||||
re_GameInfo = re.compile('- (?P<CURRENCY>\$|)?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (Ante \$(?P<ANTE>[.0-9]+) )?- (?P<LIMIT>(No Limit|Pot Limit|Limit))? (?P<GAME>(Hold\'em|Omaha Hi|Razz))')
|
re_GameInfo = re.compile('- (?P<CURRENCY>\$|)?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (Ante \$(?P<ANTE>[.0-9]+) )?- (?P<LIMIT>(No Limit|Pot Limit|Limit))? (?P<GAME>(Hold\'em|Omaha Hi|Razz))')
|
||||||
re_SplitHands = re.compile(r"\n\n+")
|
re_SplitHands = re.compile(r"(\n\n+)")
|
||||||
re_HandInfo = re.compile('.*#(?P<HID>[0-9]+): Table (?P<TABLE>[- a-zA-Z]+) (\((?P<TABLEATTRIBUTES>.+)\) )?- \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (Ante \$(?P<ANTE>[.0-9]+) )?- (?P<GAMETYPE>[a-zA-Z\' ]+) - (?P<DATETIME>.*)')
|
re_HandInfo = re.compile('.*#(?P<HID>[0-9]+): Table (?P<TABLE>[- a-zA-Z]+) (\((?P<TABLEATTRIBUTES>.+)\) )?- \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (Ante \$(?P<ANTE>[.0-9]+) )?- (?P<GAMETYPE>[a-zA-Z\' ]+) - (?P<DATETIME>.*)')
|
||||||
re_Button = re.compile('^The button is in seat #(?P<BUTTON>\d+)', re.MULTILINE)
|
re_Button = re.compile('^The button is in seat #(?P<BUTTON>\d+)', re.MULTILINE)
|
||||||
re_PlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$(?P<CASH>[.0-9]+)\)\n')
|
re_PlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$(?P<CASH>[.0-9]+)\)\n')
|
||||||
|
|
|
@ -72,7 +72,8 @@ import gettext
|
||||||
gettext.install('myapplication')
|
gettext.install('myapplication')
|
||||||
|
|
||||||
class HandHistoryConverter():
|
class HandHistoryConverter():
|
||||||
READ_CHUNK_SIZE = 1000 # bytes to read at a time from file
|
|
||||||
|
READ_CHUNK_SIZE = 10000 # bytes to read at a time from file (in tail mode)
|
||||||
def __init__(self, in_path = '-', out_path = '-', sitename = None, follow=False):
|
def __init__(self, in_path = '-', out_path = '-', sitename = None, follow=False):
|
||||||
logging.info("HandHistory init called")
|
logging.info("HandHistory init called")
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@ Tail the in_path file and yield handTexts separated by re_SplitHands"""
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
fd.seek(where)
|
fd.seek(where)
|
||||||
else:
|
else:
|
||||||
print "%s changed inode numbers from %d to %d" % (self.in_path, fd_results[1], st_results[1])
|
logging.debug("%s changed inode numbers from %d to %d" % (self.in_path, fd_results[1], st_results[1]))
|
||||||
fd = codecs.open(self.in_path, 'r', self.codepage)
|
fd = codecs.open(self.in_path, 'r', self.codepage)
|
||||||
fd.seek(where)
|
fd.seek(where)
|
||||||
else:
|
else:
|
||||||
|
@ -162,6 +163,7 @@ Tail the in_path file and yield handTexts separated by re_SplitHands"""
|
||||||
data = data + newdata
|
data = data + newdata
|
||||||
result = self.re_SplitHands.split(data)
|
result = self.re_SplitHands.split(data)
|
||||||
result = iter(result)
|
result = iter(result)
|
||||||
|
data = ''
|
||||||
# --x data (- is bit of splitter, x is paragraph) yield,...,keep
|
# --x data (- is bit of splitter, x is paragraph) yield,...,keep
|
||||||
# [,--,x] result of re.split (with group around splitter)
|
# [,--,x] result of re.split (with group around splitter)
|
||||||
# ,x our output: yield nothing, keep x
|
# ,x our output: yield nothing, keep x
|
||||||
|
@ -181,9 +183,10 @@ Tail the in_path file and yield handTexts separated by re_SplitHands"""
|
||||||
# We want to yield all paragraphs followed by a splitter, i.e. all even indices except the last.
|
# We want to yield all paragraphs followed by a splitter, i.e. all even indices except the last.
|
||||||
for para in result:
|
for para in result:
|
||||||
try:
|
try:
|
||||||
splitter = result.next()
|
result.next()
|
||||||
|
splitter = True
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
splitter = None
|
splitter = False
|
||||||
if splitter: # para is followed by a splitter
|
if splitter: # para is followed by a splitter
|
||||||
if para: yield para # para not ''
|
if para: yield para # para not ''
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -27,7 +27,7 @@ class PokerStars(HandHistoryConverter):
|
||||||
|
|
||||||
# Static regexes
|
# Static regexes
|
||||||
re_GameInfo = re.compile("PokerStars Game #(?P<HID>[0-9]+):\s+(HORSE)? \(?(?P<GAME>Hold\'em|Razz|7 Card Stud|Omaha|Omaha Hi/Lo|Badugi) (?P<LIMIT>No Limit|Limit|Pot Limit),? \(?(?P<CURRENCY>\$|)?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+)\) - (?P<DATETIME>.*$)", re.MULTILINE)
|
re_GameInfo = re.compile("PokerStars Game #(?P<HID>[0-9]+):\s+(HORSE)? \(?(?P<GAME>Hold\'em|Razz|7 Card Stud|Omaha|Omaha Hi/Lo|Badugi) (?P<LIMIT>No Limit|Limit|Pot Limit),? \(?(?P<CURRENCY>\$|)?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+)\) - (?P<DATETIME>.*$)", re.MULTILINE)
|
||||||
re_SplitHands = re.compile('\n\n+')
|
re_SplitHands = re.compile('(\n\n+)')
|
||||||
re_HandInfo = re.compile("^Table \'(?P<TABLE>[- a-zA-Z]+)\'(?P<TABLEATTRIBUTES>.+?$)?", re.MULTILINE)
|
re_HandInfo = re.compile("^Table \'(?P<TABLE>[- a-zA-Z]+)\'(?P<TABLEATTRIBUTES>.+?$)?", re.MULTILINE)
|
||||||
re_Button = re.compile('Seat #(?P<BUTTON>\d+) is the button', re.MULTILINE)
|
re_Button = re.compile('Seat #(?P<BUTTON>\d+) is the button', re.MULTILINE)
|
||||||
re_PlayerInfo = re.compile('^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$?(?P<CASH>[.0-9]+) in chips\)', re.MULTILINE)
|
re_PlayerInfo = re.compile('^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$?(?P<CASH>[.0-9]+) in chips\)', re.MULTILINE)
|
||||||
|
@ -128,7 +128,12 @@ follow : whether to tail -f the input"""
|
||||||
logging.debug("readHandInfo: %s" % info)
|
logging.debug("readHandInfo: %s" % info)
|
||||||
for key in info:
|
for key in info:
|
||||||
if key == 'DATETIME':
|
if key == 'DATETIME':
|
||||||
datetime = info[key].replace(" - "," ") # some are like "2009/02/26 - 15:22:55 ET"
|
datetime = info[key]
|
||||||
|
#2008/11/16 1:22:47 CET [2008/11/15 19:22:47 ET]
|
||||||
|
m2 = re.search(r".+\[(.+) ET\]", datetime)
|
||||||
|
if m2: datetime = m2.group(1)
|
||||||
|
#2009/02/26 - 15:22:55 ET
|
||||||
|
datetime = datetime.replace(" - "," ") # some are like "2009/02/26 - 15:22:55 ET"
|
||||||
datetime = datetime.replace(" (ET)","") # kludge for now.
|
datetime = datetime.replace(" (ET)","") # kludge for now.
|
||||||
datetime = datetime.replace(" ET","") # kludge for now.
|
datetime = datetime.replace(" ET","") # kludge for now.
|
||||||
hand.starttime = time.strptime(datetime, "%Y/%m/%d %H:%M:%S")
|
hand.starttime = time.strptime(datetime, "%Y/%m/%d %H:%M:%S")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user