diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index f8043876..d49b6219 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -15,6 +15,9 @@ #In the "official" distribution you can find the license in #agpl-3.0.txt in the docs folder of the package. +# Error logging +import sys + # String manipulation import codecs @@ -26,7 +29,7 @@ encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING) # I'm saving a few cycles with this one not_needed = False -if Configuration.LOCALE_ENCODING == 'utf-8': +if Configuration.LOCALE_ENCODING == 'UTF8': not_needed = True def to_utf8(s): @@ -37,7 +40,17 @@ def to_utf8(s): _out = unicode(s, Configuration.LOCALE_ENCODING).encode('utf-8') return _out except UnicodeDecodeError: - print 'Could not convert: "%s"' % s + sys.stderr.write('Could not convert: "%s"\n' % s) + raise + +def to_db_utf8(s): + if not_needed: return s + + try: + (_out, _len) = encoder_to_utf.encode(unicode(s)) + return _out + except UnicodeDecodeError: + sys.stderr.write('Could not convert: "%s"\n' % s) raise def to_gui(s): @@ -47,6 +60,6 @@ def to_gui(s): (_out, _len) = encoder_to_sys.encode(s) return _out except UnicodeDecodeError: - print 'Could not convert: "%s"' % s + sys.stderr.write('Could not convert: "%s"\n' % s) raise diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index ddd810ca..f17f1d33 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -71,7 +71,6 @@ import Charset from Exceptions import * log = Configuration.get_logger("logging.conf") -encoder = codecs.lookup('utf-8') DB_VERSION = 119 @@ -1751,7 +1750,7 @@ class Database: def insertPlayer(self, name, site_id): result = None - (_name, _len) = encoder.encode(unicode(name)) + _name = Charset.to_db_utf8(name) c = self.get_cursor() q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s" q = q.replace('%s', self.sql.query['placeholder']) diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index 3a331bfd..fa6d2400 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -51,6 +51,16 @@ class Filters(threading.Thread): self.heroes = {} self.boxes = {} + for site in self.conf.get_supported_sites(): + #Get db site id for filtering later + self.cursor.execute(self.sql.query['getSiteId'], (site,)) + result = self.db.cursor.fetchall() + if len(result) == 1: + self.siteid[site] = result[0][0] + else: + print "Either 0 or more than one site matched - EEK" + + # text used on screen stored here so that it can be configured self.filterText = {'limitsall':'All', 'limitsnone':'None', 'limitsshow':'Show _Limits' ,'seatsbetween':'Between:', 'seatsand':'And:', 'seatsshow':'Show Number of _Players' @@ -259,7 +269,7 @@ class Filters(threading.Thread): liststore = gtk.ListStore(gobject.TYPE_STRING) completion.set_model(liststore) completion.set_text_column(0) - names = self.db.get_player_names(self.conf) # (config=self.conf, site_id=None, like_player_name="%") + names = self.db.get_player_names(self.conf, self.siteid[site]) # (config=self.conf, site_id=None, like_player_name="%") for n in names: # list of single-element "tuples" _n = Charset.to_gui(n[0]) _nt = (_n, ) @@ -487,12 +497,12 @@ class Filters(threading.Thread): vbox.pack_start(hbox, False, True, 0) self.createSiteLine(hbox, site) #Get db site id for filtering later - self.cursor.execute(self.sql.query['getSiteId'], (site,)) - result = self.db.cursor.fetchall() - if len(result) == 1: - self.siteid[site] = result[0][0] - else: - print "Either 0 or more than one site matched - EEK" + #self.cursor.execute(self.sql.query['getSiteId'], (site,)) + #result = self.db.cursor.fetchall() + #if len(result) == 1: + # self.siteid[site] = result[0][0] + #else: + # print "Either 0 or more than one site matched - EEK" def fillGamesFrame(self, vbox): self.cursor.execute(self.sql.query['getGames']) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 3351b70f..f0eca2f1 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -147,12 +147,10 @@ class GuiGraphViewer (threading.Thread): for site in sites: if sites[site] == True: sitenos.append(siteids[site]) - c = self.db.get_cursor() _hname = Charset.to_utf8(heroes[site]) - c.execute(self.sql.query['getPlayerId'], (_hname,)) - result = c.fetchall() - if len(result) == 1: - playerids.append( int(result[0][0]) ) + result = self.db.get_player_id(self.conf, site, _hname) + if result is not None: + playerids.append(int(result)) if not sitenos: #Should probably pop up here. diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index c634538e..564513f0 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -40,7 +40,7 @@ class GuiPlayerStats (threading.Thread): self.conf = config self.main_window = mainwin self.sql = querylist - + self.liststore = [] # gtk.ListStore[] stores the contents of the grids self.listcols = [] # gtk.TreeViewColumn[][] stores the columns in the grids @@ -188,13 +188,10 @@ class GuiPlayerStats (threading.Thread): for site in sites: if sites[site] == True: sitenos.append(siteids[site]) - # Nasty hack to deal with multiple sites + same player name -Eric - que = self.sql.query['getPlayerId'] + " AND siteId=%d" % siteids[site] _hname = Charset.to_utf8(heroes[site]) - self.cursor.execute(que, (_hname,)) - result = self.db.cursor.fetchall() - if len(result) == 1: - playerids.append(result[0][0]) + result = self.db.get_player_id(self.conf, site, _hname) + if result is not None: + playerids.append(int(result)) if not sitenos: #Should probably pop up here. diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index c0374143..bec2ebae 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -440,10 +440,9 @@ or None if we fail to get the info """ #print "trying", kodec try: in_fh = codecs.open(self.in_path, 'r', kodec) - in_fh.seek(self.index) - log.debug("Opened in_path: '%s' with %s" % (self.in_path, kodec)) - self.obs = in_fh.read() - self.index = in_fh.tell() + whole_file = in_fh.read() + self.obs = whole_file[self.index:] + self.index = len(whole_file) in_fh.close() break except: diff --git a/pyfpdb/PartyPokerToFpdb.py b/pyfpdb/PartyPokerToFpdb.py index 4cf64547..3d5a959b 100755 --- a/pyfpdb/PartyPokerToFpdb.py +++ b/pyfpdb/PartyPokerToFpdb.py @@ -55,22 +55,22 @@ class PartyPoker(HandHistoryConverter): # $5 USD NL Texas Hold'em - Saturday, July 25, 07:53:52 EDT 2009 # NL Texas Hold'em $1 USD Buy-in Trny:45685440 Level:8 Blinds-Antes(600/1 200 -50) - Sunday, May 17, 11:25:07 MSKS 2009 re_GameInfoRing = re.compile(""" - (?P\$|)\s*(?P[0-9,]+)\s*(?:USD)?\s* - (?P(NL|PL|))\s+ + (?P\$|)\s*(?P[.,0-9]+)([.,0-9/$]+)?\s*(?:USD)?\s* + (?P(NL|PL|))\s* (?P(Texas\ Hold\'em|Omaha)) \s*\-\s* (?P.+) """, re.VERBOSE) re_GameInfoTrny = re.compile(""" - (?P(NL|PL|))\s+ + (?P(NL|PL|))\s* (?P(Texas\ Hold\'em|Omaha))\s+ - (?P\$?[.0-9]+)\s*(?PUSD)?\s*Buy-in\s+ + (?:(?P\$?[.,0-9]+)\s*(?PUSD)?\s*Buy-in\s+)? Trny:\s?(?P\d+)\s+ Level:\s*(?P\d+)\s+ - Blinds(?:-Antes)?\( - (?P[.0-9 ]+)\s* - /(?P[.0-9 ]+) - (?:\s*-\s*(?P[.0-9 ]+)\$?)? + ((Blinds|Stakes)(?:-Antes)?)\( + (?P[.,0-9 ]+)\s* + /(?P[.,0-9 ]+) + (?:\s*-\s*(?P[.,0-9 ]+)\$?)? \) \s*\-\s* (?P.+) @@ -85,10 +85,9 @@ class PartyPoker(HandHistoryConverter): re.VERBOSE) re_HandInfo = re.compile(""" - ^Table\s+ - (?P[a-zA-Z0-9 ]+)\s+ + ^Table\s+(?P[$a-zA-Z0-9 ]+)\s+ (?: \#|\(|)(?P\d+)\)?\s+ - (?:[^ ]+\s+\#(?P\d+).+)? # table number for mtt + (?:[a-zA-Z0-9 ]+\s+\#(?P\d+).+)? (\(No\sDP\)\s)? \((?PReal|Play)\s+Money\)\s+ # FIXME: check if play money is correct Seat\s+(?P