Add ability to import Stars archive files.

PokerStars support can provide a HH archive. The format is similar but not the same as a a standard hh format as it contains an additional line "Hand #X" between each hand.

Patch adds an option -s to GuiBulkImport, which when specified will strip these lines out and continue parsing.
This commit is contained in:
Worros 2009-12-17 18:42:50 +08:00 committed by kangaderoo
parent 4c49d7163b
commit f8dccd43a3
4 changed files with 25 additions and 7 deletions

View File

@ -326,6 +326,8 @@ def main(argv=None):
help="How often to print a one-line status report (0 (default) means never)") help="How often to print a one-line status report (0 (default) means never)")
parser.add_option("-u", "--usage", action="store_true", dest="usage", default=False, parser.add_option("-u", "--usage", action="store_true", dest="usage", default=False,
help="Print some useful one liners") help="Print some useful one liners")
parser.add_option("-s", "--starsarchive", action="store_true", dest="starsArchive", default=False,
help="Do the required conversion for Stars Archive format (ie. as provided by support")
(options, argv) = parser.parse_args(args = argv) (options, argv) = parser.parse_args(args = argv)
if options.usage == True: if options.usage == True:
@ -369,6 +371,8 @@ def main(argv=None):
importer.setThreads(-1) importer.setThreads(-1)
importer.addBulkImportImportFileOrDir(os.path.expanduser(options.filename), site=options.filtername) importer.addBulkImportImportFileOrDir(os.path.expanduser(options.filename), site=options.filtername)
importer.setCallHud(False) importer.setCallHud(False)
if options.starsArchive:
importer.setStarsArchive(True)
(stored, dups, partial, errs, ttime) = importer.runImport() (stored, dups, partial, errs, ttime) = importer.runImport()
importer.clearFileList() importer.clearFileList()
print 'GuiBulkImport done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %.0f/sec'\ print 'GuiBulkImport done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %.0f/sec'\

View File

@ -266,6 +266,7 @@ If a player has None chips he won't be added."""
log.error("markstreets didn't match") log.error("markstreets didn't match")
log.error(" - Assuming hand cancelled") log.error(" - Assuming hand cancelled")
self.cancelled = True self.cancelled = True
raise FpdbParseError
def checkPlayerExists(self,player): def checkPlayerExists(self,player):
if player not in [p[1] for p in self.players]: if player not in [p[1] for p in self.players]:

View File

@ -57,7 +57,7 @@ class HandHistoryConverter():
codepage = "cp1252" codepage = "cp1252"
def __init__(self, in_path = '-', out_path = '-', follow=False, index=0, autostart=True): def __init__(self, in_path = '-', out_path = '-', follow=False, index=0, autostart=True, starsArchive=False):
"""\ """\
in_path (default '-' = sys.stdin) in_path (default '-' = sys.stdin)
out_path (default '-' = sys.stdout) out_path (default '-' = sys.stdout)
@ -66,6 +66,7 @@ follow : whether to tail -f the input"""
log.info("HandHistory init - %s subclass, in_path '%s'; out_path '%s'" % (self.sitename, in_path, out_path) ) log.info("HandHistory init - %s subclass, in_path '%s'; out_path '%s'" % (self.sitename, in_path, out_path) )
self.index = 0 self.index = 0
self.starsArchive = starsArchive
self.in_path = in_path self.in_path = in_path
self.out_path = out_path self.out_path = out_path
@ -254,6 +255,11 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
self.readFile() self.readFile()
self.obs = self.obs.strip() self.obs = self.obs.strip()
self.obs = self.obs.replace('\r\n', '\n') self.obs = self.obs.replace('\r\n', '\n')
if self.starsArchive == True:
log.debug("Converting starsArchive format to readable")
m = re.compile('^Hand #\d+', re.MULTILINE)
self.obs = m.sub('', self.obs)
if self.obs is None or self.obs == "": if self.obs is None or self.obs == "":
log.info("Read no hands.") log.info("Read no hands.")
return [] return []

View File

@ -91,6 +91,7 @@ class Importer:
self.settings.setdefault("writeQMaxWait", 10) # not used self.settings.setdefault("writeQMaxWait", 10) # not used
self.settings.setdefault("dropIndexes", "don't drop") self.settings.setdefault("dropIndexes", "don't drop")
self.settings.setdefault("dropHudCache", "don't drop") self.settings.setdefault("dropHudCache", "don't drop")
self.settings.setdefault("starsArchive", False)
self.writeq = None self.writeq = None
self.database = Database.Database(self.config, sql = self.sql) self.database = Database.Database(self.config, sql = self.sql)
@ -134,6 +135,9 @@ class Importer:
def setDropHudCache(self, value): def setDropHudCache(self, value):
self.settings['dropHudCache'] = value self.settings['dropHudCache'] = value
def setStarsArchive(self, value):
self.settings['starsArchive'] = value
# def setWatchTime(self): # def setWatchTime(self):
# self.updated = time() # self.updated = time()
@ -425,7 +429,7 @@ class Importer:
mod = __import__(filter) mod = __import__(filter)
obj = getattr(mod, filter_name, None) obj = getattr(mod, filter_name, None)
if callable(obj): if callable(obj):
hhc = obj(in_path = file, out_path = out_path, index = 0) # Index into file 0 until changeover hhc = obj(in_path = file, out_path = out_path, index = 0, starsArchive = self.settings['starsArchive']) # Index into file 0 until changeover
if hhc.getStatus() and self.NEWIMPORT == False: if hhc.getStatus() and self.NEWIMPORT == False:
(stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(db, out_path, site, q) (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(db, out_path, site, q)
elif hhc.getStatus() and self.NEWIMPORT == True: elif hhc.getStatus() and self.NEWIMPORT == True:
@ -435,11 +439,14 @@ class Importer:
to_hud = [] to_hud = []
for hand in handlist: for hand in handlist:
if hand is not None:
#try, except duplicates here? #try, except duplicates here?
hand.prepInsert(self.database) hand.prepInsert(self.database)
hand.insert(self.database) hand.insert(self.database)
if self.callHud and hand.dbid_hands != 0: if self.callHud and hand.dbid_hands != 0:
to_hud.append(hand.dbid_hands) to_hud.append(hand.dbid_hands)
else:
log.error("Hand processed but empty")
self.database.commit() self.database.commit()
#pipe the Hands.id out to the HUD #pipe the Hands.id out to the HUD