From 61b0b8f4fe35171873300c88238b401ba349d040 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 17 Jul 2009 17:16:06 +0800 Subject: [PATCH 1/3] Prep work for inserting directly from HHC --- pyfpdb/fpdb_import.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 3129c22c..8323a790 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -83,6 +83,8 @@ class Importer: self.fdb.do_connect(self.config) self.fdb.db.rollback() + self.NEWIMPORT = False + #Set functions def setCallHud(self, value): self.callHud = value @@ -311,8 +313,16 @@ class Importer: obj = getattr(mod, filter_name, None) if callable(obj): conv = obj(in_path = file, out_path = out_path) - if(conv.getStatus()): + if(conv.getStatus() and self.NEWIMPORT == False): (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) + elif (conv.getStatus() and self.NEWIMPORT == True): + #This code doesn't do anything yet + handlist = hhc.getProcessedHands() + self.pos_in_file[file] = hhc.getLastCharacterRead() + + for hand in handlist: + hand.prepInsert() + hand.insert() else: # conversion didn't work # TODO: appropriate response? From 34932c14eeace93d3f0e48bd1ad360ba2a4a3687 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 17 Jul 2009 17:45:22 +0800 Subject: [PATCH 2/3] Add index parameter to Plugins Change constructor to HHC to accept an index arg, so that file reads can seek --- pyfpdb/BetfairToFpdb.py | 4 ++-- pyfpdb/EverleafToFpdb.py | 4 ++-- pyfpdb/FulltiltToFpdb.py | 4 ++-- pyfpdb/HandHistoryConverter.py | 8 +++++++- pyfpdb/PokerStarsToFpdb.py | 4 ++-- pyfpdb/UltimateBetToFpdb.py | 4 ++-- pyfpdb/Win2dayToFpdb.py | 4 ++-- pyfpdb/fpdb_import.py | 2 +- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pyfpdb/BetfairToFpdb.py b/pyfpdb/BetfairToFpdb.py index 672e858a..1ccec5d0 100755 --- a/pyfpdb/BetfairToFpdb.py +++ b/pyfpdb/BetfairToFpdb.py @@ -34,12 +34,12 @@ class Betfair(HandHistoryConverter): re_PlayerInfo = re.compile("Seat (?P[0-9]+): (?P.*)\s\(\s(\$(?P[.0-9]+)) \)") re_Board = re.compile(ur"\[ (?P.+) \]") - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True): + def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, index=0): """\ in_path (default '-' = sys.stdin) out_path (default '-' = sys.stdout) follow : whether to tail -f the input""" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="Betfair", follow=follow) # Call super class init. + HandHistoryConverter.__init__(self, in_path, out_path, sitename="Betfair", follow=follow, index) # Call super class init. logging.info("Initialising Betfair converter class") self.filetype = "text" self.codepage = "cp1252" diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index ee4942f1..10468378 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -37,7 +37,7 @@ class Everleaf(HandHistoryConverter): re_Board = re.compile(ur"\[ (?P.+) \]") - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, debugging=False): + def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, debugging=False, index=0): """\ in_path (default '-' = sys.stdin) out_path (default '-' = sys.stdout) @@ -45,7 +45,7 @@ follow : whether to tail -f the input autostart: whether to run the thread (or you can call start() yourself) debugging: if False, pass on partially supported game types. If true, have a go and error...""" print "DEBUG: XXXXXXXXXXXXXXX" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="Everleaf", follow=follow) + HandHistoryConverter.__init__(self, in_path, out_path, sitename="Everleaf", follow=follow, index=index) logging.info("Initialising Everleaf converter class") self.filetype = "text" self.codepage = "cp1252" diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index f7b834a6..173489f7 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -36,12 +36,12 @@ class Fulltilt(HandHistoryConverter): re_Board = re.compile(r"\[(?P.+)\]") # NB: if we ever match "Full Tilt Poker" we should also match "FullTiltPoker", which PT Stud erroneously exports. - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True): + def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, index=0): """\ in_path (default '-' = sys.stdin) out_path (default '-' = sys.stdout) follow : whether to tail -f the input""" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="Fulltilt", follow=follow) + HandHistoryConverter.__init__(self, in_path, out_path, sitename="Fulltilt", follow=follow, index=index) logging.info("Initialising Fulltilt converter class") self.filetype = "text" self.codepage = "cp1252" diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 94ca5fec..712260f9 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -37,12 +37,13 @@ gettext.install('fpdb') class HandHistoryConverter(): 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, index=0): logging.info("HandHistory init") # default filetype and codepage. Subclasses should set these properly. self.filetype = "text" self.codepage = "utf8" + self.index = 0 self.in_path = in_path self.out_path = out_path @@ -330,7 +331,9 @@ or None if we fail to get the info """ else: logging.debug("Opening %s with %s" % (self.in_path, self.codepage)) in_fh = codecs.open(self.in_path, 'r', self.codepage) + in_fh.seek(self.index) self.obs = in_fh.read() + self.index = in_fh.tell() in_fh.close() elif(self.filetype == "xml"): try: @@ -346,3 +349,6 @@ or None if we fail to get the info """ def getProcessedFile(self): return self.out_path + + def getLastCharacterRead(self): + return self.index diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index b855586b..4e1bbf29 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -55,12 +55,12 @@ class PokerStars(HandHistoryConverter): mixes = { 'HORSE': 'horse', '8-Game': '8game', 'HOSE': 'hose'} - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True): + def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, index=0): """\ in_path (default '-' = sys.stdin) out_path (default '-' = sys.stdout) follow : whether to tail -f the input""" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="PokerStars", follow=follow) + HandHistoryConverter.__init__(self, in_path, out_path, sitename="PokerStars", follow=follow, index=index) logging.info("Initialising PokerStars converter class") self.filetype = "text" self.codepage = "cp1252" diff --git a/pyfpdb/UltimateBetToFpdb.py b/pyfpdb/UltimateBetToFpdb.py index b57e789e..cce2df4c 100755 --- a/pyfpdb/UltimateBetToFpdb.py +++ b/pyfpdb/UltimateBetToFpdb.py @@ -33,12 +33,12 @@ class UltimateBet(HandHistoryConverter): re_Board = re.compile(r"\[(?P.+)\]") # self.re_setHandInfoRegex('.*#(?P[0-9]+): Table (?P[ a-zA-Z]+) - \$?(?P[.0-9]+)/\$?(?P[.0-9]+) - (?P.*) - (?P
[0-9]+):(?P[0-9]+) ET - (?P[0-9]+)/(?P[0-9]+)/(?P[0-9]+)Table (?P
[ a-zA-Z]+)\nSeat (?P