Merge branch 'master' of git://git.assembla.com/free_poker_tools

This commit is contained in:
Mika Bostrom 2009-08-22 17:41:31 +03:00
commit 777b7b726a
8 changed files with 315 additions and 118 deletions

View File

@ -29,7 +29,7 @@ class Fulltilt(HandHistoryConverter):
sitename = "Fulltilt" sitename = "Fulltilt"
filetype = "text" filetype = "text"
codepage = "cp1252" codepage = "utf-16"
siteId = 1 # Needs to match id entry in Sites database siteId = 1 # Needs to match id entry in Sites database
# Static regexes # Static regexes
@ -57,7 +57,8 @@ class Fulltilt(HandHistoryConverter):
(?:.*?\n(?P<CANCELLED>Hand\s\#(?P=HID)\shas\sbeen\scanceled))? (?:.*?\n(?P<CANCELLED>Hand\s\#(?P=HID)\shas\sbeen\scanceled))?
''', re.VERBOSE|re.DOTALL) ''', re.VERBOSE|re.DOTALL)
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]+)\)', re.MULTILINE) re_PlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$(?P<CASH>[,.0-9]+)\)$', re.MULTILINE)
re_TourneyPlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$?(?P<CASH>[,.0-9]+)\)', re.MULTILINE)
re_Board = re.compile(r"\[(?P<CARDS>.+)\]") re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
# These regexes are for FTP only # These regexes are for FTP only
@ -65,6 +66,9 @@ class Fulltilt(HandHistoryConverter):
re_Max = re.compile("(?P<MAX>\d+)( max)?", re.MULTILINE) re_Max = re.compile("(?P<MAX>\d+)( max)?", re.MULTILINE)
# NB: if we ever match "Full Tilt Poker" we should also match "FullTiltPoker", which PT Stud erroneously exports. # NB: if we ever match "Full Tilt Poker" we should also match "FullTiltPoker", which PT Stud erroneously exports.
mixes = { 'HORSE': 'horse', '7-Game': '7game', 'HOSE': 'hose', 'HA': 'ha'} mixes = { 'HORSE': 'horse', '7-Game': '7game', 'HOSE': 'hose', 'HA': 'ha'}
@ -137,24 +141,6 @@ class Fulltilt(HandHistoryConverter):
# if info['type'] == "tour": return None # importer is screwed on tournies, pass on those hands so we don't interrupt other autoimporting # if info['type'] == "tour": return None # importer is screwed on tournies, pass on those hands so we don't interrupt other autoimporting
return info return info
#Following function is a hack, we should be dealing with this in readFile (i think correct codepage....)
# Same function as parent class, removing the 2 end characters. - CG
def allHandsAsList(self):
"""Return a list of handtexts in the file at self.in_path"""
#TODO : any need for this to be generator? e.g. stars support can email one huge file of all hands in a year. Better to read bit by bit than all at once.
self.readFile()
# FIXME: it's a hack
if self.obs[:2] == u'\xff\xfe':
self.obs = self.obs[2:].replace('\x00', '')
self.obs = self.obs.strip()
self.obs = self.obs.replace('\r\n', '\n')
if self.obs == "" or self.obs == None:
logging.info("Read no hands.")
return []
return re.split(self.re_SplitHands, self.obs)
def readHandInfo(self, hand): def readHandInfo(self, hand):
m = self.re_HandInfo.search(hand.handText) m = self.re_HandInfo.search(hand.handText)
if(m == None): if(m == None):
@ -208,7 +194,11 @@ class Fulltilt(HandHistoryConverter):
#FIXME: hand.buttonpos = int(m.group('BUTTON')) #FIXME: hand.buttonpos = int(m.group('BUTTON'))
def readPlayerStacks(self, hand): def readPlayerStacks(self, hand):
m = self.re_PlayerInfo.finditer(hand.handText) if hand.gametype['type'] == "ring" :
m = self.re_PlayerInfo.finditer(hand.handText)
else: #if hand.gametype['type'] == "tour"
m = self.re_TourneyPlayerInfo.finditer(hand.handText)
players = [] players = []
for a in m: for a in m:
hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH')) hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH'))

View File

@ -302,14 +302,13 @@ If a player has None chips he won't be added."""
return c return c
def addAnte(self, player, ante): def addAnte(self, player, ante):
log.debug("%s %s antes %s" % ('ANTES', player, ante)) log.debug("%s %s antes %s" % ('BLINDSANTES', player, ante))
if player is not None: if player is not None:
ante = re.sub(u',', u'', ante) #some sites have commas ante = re.sub(u',', u'', ante) #some sites have commas
self.bets['ANTES'][player].append(Decimal(ante)) self.bets['BLINDSANTES'][player].append(Decimal(ante))
self.stacks[player] -= Decimal(ante) self.stacks[player] -= Decimal(ante)
act = (player, 'posts', "ante", ante, self.stacks[player]==0) act = (player, 'posts', "ante", ante, self.stacks[player]==0)
self.actions['ANTES'].append(act) self.actions['BLINDSANTES'].append(act)
#~ self.lastBet['ANTES'] = Decimal(ante)
self.pot.addMoney(player, Decimal(ante)) self.pot.addMoney(player, Decimal(ante))
def addBlind(self, player, blindtype, amount): def addBlind(self, player, blindtype, amount):
@ -324,19 +323,19 @@ If a player has None chips he won't be added."""
log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount)) log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
if player is not None: if player is not None:
amount = re.sub(u',', u'', amount) #some sites have commas amount = re.sub(u',', u'', amount) #some sites have commas
self.bets['PREFLOP'][player].append(Decimal(amount))
self.stacks[player] -= Decimal(amount) self.stacks[player] -= Decimal(amount)
#print "DEBUG %s posts, stack %s" % (player, self.stacks[player])
act = (player, 'posts', blindtype, amount, self.stacks[player]==0) act = (player, 'posts', blindtype, amount, self.stacks[player]==0)
self.actions['BLINDSANTES'].append(act) self.actions['BLINDSANTES'].append(act)
if blindtype == 'both':
amount = self.bb
self.bets['BLINDSANTES'][player].append(Decimal(self.sb))
self.pot.addCommonMoney(Decimal(self.sb))
self.bets['PREFLOP'][player].append(Decimal(amount))
self.pot.addMoney(player, Decimal(amount)) self.pot.addMoney(player, Decimal(amount))
if blindtype == 'big blind': self.lastBet['PREFLOP'] = Decimal(amount)
self.lastBet['PREFLOP'] = Decimal(amount)
elif blindtype == 'both':
# extra small blind is 'dead'
self.lastBet['PREFLOP'] = Decimal(self.bb)
self.posted = self.posted + [[player,blindtype]] self.posted = self.posted + [[player,blindtype]]
#print "DEBUG: self.posted: %s" %(self.posted)
@ -472,6 +471,7 @@ Add a raise on [street] by [player] to [amountTo]
For when a player shows cards for any reason (for showdown or out of choice). For when a player shows cards for any reason (for showdown or out of choice).
Card ranks will be uppercased Card ranks will be uppercased
""" """
import sys; sys.exit(1)
log.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard)) log.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard))
if cards is not None: if cards is not None:
self.addHoleCards(cards,player,shown, mucked) self.addHoleCards(cards,player,shown, mucked)
@ -552,6 +552,8 @@ Map the tuple self.gametype onto the pokerstars string describing it
return ("%s: posts big blind %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else '')) return ("%s: posts big blind %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else ''))
elif(act[2] == "both"): elif(act[2] == "both"):
return ("%s: posts small & big blinds %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else '')) return ("%s: posts small & big blinds %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else ''))
elif(act[2] == "ante"):
return ("%s: posts the ante %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else ''))
elif act[1] == 'bringin': elif act[1] == 'bringin':
return ("%s: brings in for %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) return ("%s: brings in for %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else ''))
elif act[1] == 'discards': elif act[1] == 'discards':
@ -621,6 +623,7 @@ class HoldemOmahaHand(Hand):
hhc.compilePlayerRegexs(self) hhc.compilePlayerRegexs(self)
hhc.markStreets(self) hhc.markStreets(self)
hhc.readBlinds(self) hhc.readBlinds(self)
hhc.readAntes(self)
hhc.readButton(self) hhc.readButton(self)
hhc.readHeroCards(self) hhc.readHeroCards(self)
hhc.readShowdownActions(self) hhc.readShowdownActions(self)
@ -885,6 +888,7 @@ class DrawHand(Hand):
hhc.compilePlayerRegexs(self) hhc.compilePlayerRegexs(self)
hhc.markStreets(self) hhc.markStreets(self)
hhc.readBlinds(self) hhc.readBlinds(self)
hhc.readAntes(self)
hhc.readButton(self) hhc.readButton(self)
hhc.readHeroCards(self) hhc.readHeroCards(self)
hhc.readShowdownActions(self) hhc.readShowdownActions(self)
@ -1042,11 +1046,11 @@ class StudHand(Hand):
if gametype['base'] != 'stud': if gametype['base'] != 'stud':
pass # or indeed don't pass and complain instead pass # or indeed don't pass and complain instead
self.allStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] self.allStreets = ['BLINDSANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH']
self.communityStreets = [] self.communityStreets = []
self.actionStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] self.actionStreets = ['BLINDSANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH']
self.streetList = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] # a list of the observed street names in order self.streetList = ['BLINDSANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] # a list of the observed street names in order
self.holeStreets = ['THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] self.holeStreets = ['THIRD','FOURTH','FIFTH','SIXTH','SEVENTH']
Hand.__init__(self, sitename, gametype, handText) Hand.__init__(self, sitename, gametype, handText)
self.sb = gametype['sb'] self.sb = gametype['sb']
@ -1064,7 +1068,7 @@ class StudHand(Hand):
hhc.readHeroCards(self) hhc.readHeroCards(self)
# Read actions in street order # Read actions in street order
for street in self.actionStreets: for street in self.actionStreets:
if street == 'ANTES': continue # OMG--sometime someone folds in the ante round if street == 'BLINDSANTES': continue # OMG--sometime someone folds in the ante round
if self.streets[street]: if self.streets[street]:
log.debug(street + self.streets[street]) log.debug(street + self.streets[street])
hhc.readAction(self, street) hhc.readAction(self, street)
@ -1153,14 +1157,14 @@ Add a complete on [street] by [player] to [amountTo]
super(StudHand, self).writeHand(fh) super(StudHand, self).writeHand(fh)
players_who_post_antes = set([x[0] for x in self.actions['ANTES']]) players_who_post_antes = set([x[0] for x in self.actions['BLINDSANTES']])
for player in [x for x in self.players if x[1] in players_who_post_antes]: for player in [x for x in self.players if x[1] in players_who_post_antes]:
#Only print stacks of players who do something preflop #Only print stacks of players who do something preflop
print >>fh, _("Seat %s: %s (%s%s in chips)" %(player[0], player[1], self.sym, player[2])) print >>fh, _("Seat %s: %s (%s%s in chips)" %(player[0], player[1], self.sym, player[2]))
if 'ANTES' in self.actions: if 'BLINDSANTES' in self.actions:
for act in self.actions['ANTES']: for act in self.actions['BLINDSANTES']:
print >>fh, _("%s: posts the ante %s%s" %(act[0], self.sym, act[3])) print >>fh, _("%s: posts the ante %s%s" %(act[0], self.sym, act[3]))
if 'THIRD' in self.actions: if 'THIRD' in self.actions:
@ -1308,6 +1312,7 @@ class Pot(object):
self.contenders = set() self.contenders = set()
self.committed = {} self.committed = {}
self.streettotals = {} self.streettotals = {}
self.common = Decimal(0)
self.total = None self.total = None
self.returned = {} self.returned = {}
self.sym = u'$' # this is the default currency symbol self.sym = u'$' # this is the default currency symbol
@ -1322,13 +1327,16 @@ class Pot(object):
# addFold must be called when a player folds # addFold must be called when a player folds
self.contenders.discard(player) self.contenders.discard(player)
def addCommonMoney(self, amount):
self.common += amount
def addMoney(self, player, amount): def addMoney(self, player, amount):
# addMoney must be called for any actions that put money in the pot, in the order they occur # addMoney must be called for any actions that put money in the pot, in the order they occur
self.contenders.add(player) self.contenders.add(player)
self.committed[player] += amount self.committed[player] += amount
def markTotal(self, street): def markTotal(self, street):
self.streettotals[street] = sum(self.committed.values()) self.streettotals[street] = sum(self.committed.values()) + self.common
def getTotalAtStreet(self, street): def getTotalAtStreet(self, street):
if street in self.streettotals: if street in self.streettotals:
@ -1336,7 +1344,7 @@ class Pot(object):
return 0 return 0
def end(self): def end(self):
self.total = sum(self.committed.values()) self.total = sum(self.committed.values()) + self.common
# Return any uncalled bet. # Return any uncalled bet.
committed = sorted([ (v,k) for (k,v) in self.committed.items()]) committed = sorted([ (v,k) for (k,v) in self.committed.items()])

View File

@ -408,9 +408,11 @@ class Stat_Window:
if event.button == 3: # right button event if event.button == 3: # right button event
self.popups.append(Popup_window(widget, self)) self.popups.append(Popup_window(widget, self))
return True
if event.button == 2: # middle button event if event.button == 2: # middle button event
self.window.hide() self.window.hide()
return True
if event.button == 1: # left button event if event.button == 1: # left button event
# TODO: make position saving save sizes as well? # TODO: make position saving save sizes as well?
@ -418,6 +420,11 @@ class Stat_Window:
self.window.begin_resize_drag(gtk.gdk.WINDOW_EDGE_SOUTH_EAST, event.button, int(event.x_root), int(event.y_root), event.time) self.window.begin_resize_drag(gtk.gdk.WINDOW_EDGE_SOUTH_EAST, event.button, int(event.x_root), int(event.y_root), event.time)
else: else:
self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time) self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
return True
return False
def noop(self): # i'm going to try to connect the focus-in and focus-out events here, to see if that fixes any of the focus problems.
return True
def kill_popup(self, popup): def kill_popup(self, popup):
popup.window.destroy() popup.window.destroy()
@ -493,9 +500,16 @@ class Stat_Window:
e_box[r][c].add(self.label[r][c]) e_box[r][c].add(self.label[r][c])
e_box[r][c].connect("button_press_event", self.button_press_cb) e_box[r][c].connect("button_press_event", self.button_press_cb)
e_box[r][c].connect("focus-in-event", self.noop)
e_box[r][c].connect("focus", self.noop)
e_box[r][c].connect("focus-out-event", self.noop)
label[r][c].modify_font(font) label[r][c].modify_font(font)
self.window.set_opacity(parent.colors['hudopacity']) self.window.set_opacity(parent.colors['hudopacity'])
self.window.connect("focus", self.noop)
self.window.connect("focus-in-event", self.noop)
self.window.connect("focus-out-event", self.noop)
self.window.connect("button_press_event", self.button_press_cb)
self.window.move(self.x, self.y) self.window.move(self.x, self.y)
@ -596,7 +610,9 @@ class Popup_window:
if event.button == 3: # right button event if event.button == 3: # right button event
self.stat_window.kill_popup(self) self.stat_window.kill_popup(self)
return True
# self.window.destroy() # self.window.destroy()
return False
def toggle_decorated(self, widget): def toggle_decorated(self, widget):
top = widget.get_toplevel() top = widget.get_toplevel()

View File

@ -1587,6 +1587,9 @@ class Sql:
# used in GuiPlayerStats: # used in GuiPlayerStats:
self.query['getPlayerId'] = """SELECT id from Players where name = %s""" self.query['getPlayerId'] = """SELECT id from Players where name = %s"""
self.query['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s"""
# used in Filters: # used in Filters:
self.query['getSiteId'] = """SELECT id from Sites where name = %s""" self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
self.query['getGames'] = """SELECT DISTINCT category from Gametypes""" self.query['getGames'] = """SELECT DISTINCT category from Gametypes"""

184
pyfpdb/Summary-Everleaf.py Normal file
View File

@ -0,0 +1,184 @@
#!/usr/bin/python
# Copyright (c) 2009 Eric Blade, and the FPDB team.
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
import urllib, htmllib, formatter
class AppURLopener(urllib.FancyURLopener):
version = "Free Poker Database/0.12+"
urllib._urlopener = AppURLopener()
class SummaryParser(htmllib.HTMLParser): # derive new HTML parser
def get_attr(self, attrs, key):
#print attrs;
for a in attrs:
if a[0] == key:
# print key,"=",a[1]
return a[1]
return None
def __init__(self, formatter) : # class constructor
htmllib.HTMLParser.__init__(self, formatter) # base class constructor
self.nofill = True
self.SiteName = None
self.TourneyId = None
self.TourneyName = None
self.nextStartTime = False
self.TourneyStartTime = None
self.nextEndTime = False
self.TourneyEndTime = None
self.TourneyGameType = None
self.nextGameType = False
self.nextStructure = False
self.TourneyStructure = None
self.nextBuyIn = False
self.TourneyBuyIn = None
self.nextPool = False
self.TourneyPool = None
self.nextPlayers = False
self.TourneyPlayers = None
self.nextAllowRebuys = False
self.TourneyRebuys = None
self.parseResultsA = False
self.parseResultsB = False
self.TempResultStore = [0,0,0,0]
self.TempResultPos = 0
self.Results = {}
def start_meta(self, attrs):
x = self.get_attr(attrs, 'name')
if x == "author":
self.SiteName = self.get_attr(attrs, 'content')
def start_input(self, attrs):
x = self.get_attr(attrs, 'name')
#print "input name=",x
if x == "tid":
self.TourneyId = self.get_attr(attrs, 'value')
def start_h1(self, attrs):
if self.TourneyName is None:
self.save_bgn()
def end_h1(self):
if self.TourneyName is None:
self.TourneyName = self.save_end()
def start_div(self, attrs):
x = self.get_attr(attrs, 'id')
if x == "result":
self.parseResultsA = True
def end_div(self): # TODO: Can we get attrs in the END tag too? I don't know? Would be useful to make SURE we're closing the right div ..
if self.parseResultsA:
self.parseResultsA = False # TODO: Should probably just make sure everything is false at this point, since we're not going to be having anything in the middle of a DIV.. oh well
def start_td(self, attrs):
self.save_bgn()
def end_td(self):
x = self.save_end()
if not self.parseResultsA:
if not self.nextStartTime and x == "Start:":
self.nextStartTime = True
elif self.nextStartTime:
self.TourneyStartTime = x
self.nextStartTime = False
if not self.nextEndTime and x == "Finished:":
self.nextEndTime = True
elif self.nextEndTime:
self.TourneyEndTime = x
self.nextEndTime = False
if not self.nextGameType and x == "Game Type:":
self.nextGameType = True
elif self.nextGameType:
self.TourneyGameType = x
self.nextGameType = False
if not self.nextStructure and x == "Limit:":
self.nextStructure = True
elif self.nextStructure:
self.TourneyStructure = x
self.nextStructure = False
if not self.nextBuyIn and x == "Buy In / Fee:":
self.nextBuyIn = True
elif self.nextBuyIn:
self.TourneyBuyIn = x # TODO: Further parse the fee from this
self.nextBuyIn = False
if not self.nextPool and x == "Prize Money:":
self.nextPool = True
elif self.nextPool:
self.TourneyPool = x
self.nextPool = False
if not self.nextPlayers and x == "Player Count:":
self.nextPlayers = True
elif self.nextPlayers:
self.TourneyPlayers = x
self.nextPlayers = False
if not self.nextAllowRebuys and x == "Rebuys possible?:":
self.nextAllowRebuys = True
elif self.nextAllowRebuys:
self.TourneyRebuys = x
self.nextAllowRebuys = False
else: # parse results
if x == "Won Prize":
self.parseResultsB = True # ok, NOW we can start parsing the results
elif self.parseResultsB:
if x[0] == "$": # first char of the last of each row is the dollar sign, so now we can put it into a sane order
self.TempResultPos = 0
name = self.TempResultStore[1]
place = self.TempResultStore[0]
time = self.TempResultStore[2]
# print self.TempResultStore
self.Results[name] = {}
self.Results[name]['place'] = place
self.Results[name]['winamount'] = x
self.Results[name]['outtime'] = time
# self.Results[self.TempResultStore[1]] = {}
# self.Results[self.TempResultStore[1]]['place'] = self.TempResultStore[self.TempResultStore[0]]
# self.Results[self.TempResultStore[1]]['winamount'] = x
# self.Results[self.TempResultStore[1]]['outtime'] = self.TempResultStore[self.TempResultStore[2]]
else:
self.TempResultStore[self.TempResultPos] = x
self.TempResultPos += 1
class EverleafSummary:
def main(self):
file = urllib.urlopen("http://www.poker4ever.com/en.tournaments.tournament-statistics?tid=785119")
parser = SummaryParser(formatter.NullFormatter())
parser.feed(file.read())
print "site=",parser.SiteName, "tourneyname=", parser.TourneyName, "tourneyid=", parser.TourneyId
print "start time=",parser.TourneyStartTime, "end time=",parser.TourneyEndTime
print "structure=", parser.TourneyStructure, "game type=",parser.TourneyGameType
print "buy-in=", parser.TourneyBuyIn, "rebuys=", parser.TourneyRebuys, "total players=", parser.TourneyPlayers, "pool=", parser.TourneyPool
print "results=", parser.Results
if __name__ == "__main__":
me = EverleafSummary()
me.main()

View File

@ -39,6 +39,7 @@ if os.name == 'nt':
# FreePokerTools modules # FreePokerTools modules
import Configuration import Configuration
from fpdb_simple import LOCALE_ENCODING
# Each TableWindow object must have the following attributes correctly populated: # Each TableWindow object must have the following attributes correctly populated:
# tw.name = the table name from the title bar, which must to match the table name # tw.name = the table name from the title bar, which must to match the table name
@ -231,19 +232,12 @@ def discover_nt_by_name(c, tablename):
titles = {} titles = {}
win32gui.EnumWindows(win_enum_handler, titles) win32gui.EnumWindows(win_enum_handler, titles)
def getDefaultEncoding():
# FIXME: if somebody know better place fot this function - move it
# FIXME: it's better to use GetCPInfo for windows http://msdn.microsoft.com/en-us/library/dd318078(VS.85).aspx
# but i have no idea, how to call it
import locale
return locale.getpreferredencoding()
for hwnd in titles: for hwnd in titles:
#print "Tables.py: tablename =", tablename, "title =", titles[hwnd] #print "Tables.py: tablename =", tablename, "title =", titles[hwnd]
try: try:
# maybe it's better to make global titles[hwnd] decoding? # maybe it's better to make global titles[hwnd] decoding?
# this can blow up in XP on some windows, eg firefox displaying http://docs.python.org/tutorial/classes.html # this can blow up in XP on some windows, eg firefox displaying http://docs.python.org/tutorial/classes.html
if not tablename.lower() in titles[hwnd].decode(getDefaultEncoding()).lower(): continue if not tablename.lower() in titles[hwnd].decode(LOCALE_ENCODING).lower(): continue
except: except:
continue continue
if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window

View File

@ -380,8 +380,9 @@ class Importer:
conv = None conv = None
(stored, duplicates, partial, errors, ttime) = (0, 0, 0, 0, 0) (stored, duplicates, partial, errors, ttime) = (0, 0, 0, 0, 0)
# Load filter, process file, pass returned filename to import_fpdb_file file = file.decode(fpdb_simple.LOCALE_ENCODING)
# Load filter, process file, pass returned filename to import_fpdb_file
if self.settings['threads'] > 0 and self.writeq != None: if self.settings['threads'] > 0 and self.writeq != None:
print "\nConverting " + file + " (" + str(q.qsize()) + ")" print "\nConverting " + file + " (" + str(q.qsize()) + ")"
else: else:

View File

@ -38,7 +38,7 @@ MYSQL_INNODB = 2
PGSQL = 3 PGSQL = 3
SQLITE = 4 SQLITE = 4
(localename, encoding) = locale.getdefaultlocale() LOCALE_ENCODING = locale.getdefaultlocale()[1]
class DuplicateError(Exception): class DuplicateError(Exception):
def __init__(self, value): def __init__(self, value):
@ -546,7 +546,7 @@ def parseActionType(line):
#parses the ante out of the given line and checks which player paid it, updates antes accordingly. #parses the ante out of the given line and checks which player paid it, updates antes accordingly.
def parseAnteLine(line, isTourney, names, antes): def parseAnteLine(line, isTourney, names, antes):
for i, name in enumerate(names): for i, name in enumerate(names):
if line.startswith(name.encode(encoding)): if line.startswith(name.encode(LOCALE_ENCODING)):
pos = line.rfind("$") + 1 pos = line.rfind("$") + 1
if not isTourney: if not isTourney:
antes[i] += float2int(line[pos:]) antes[i] += float2int(line[pos:])
@ -708,7 +708,7 @@ def parseHandStartTime(topline):
def findName(line): def findName(line):
pos1 = line.find(":") + 2 pos1 = line.find(":") + 2
pos2 = line.rfind("(") - 1 pos2 = line.rfind("(") - 1
return unicode(line[pos1:pos2], encoding) return unicode(line[pos1:pos2], LOCALE_ENCODING)
def parseNames(lines): def parseNames(lines):
return [findName(line) for line in lines] return [findName(line) for line in lines]
@ -825,7 +825,7 @@ def parseTourneyNo(topline):
def parseWinLine(line, names, winnings, isTourney): def parseWinLine(line, names, winnings, isTourney):
#print "parseWinLine: line:",line #print "parseWinLine: line:",line
for i,n in enumerate(names): for i,n in enumerate(names):
n = n.encode(encoding) n = n.encode(LOCALE_ENCODING)
if line.startswith(n): if line.startswith(n):
if isTourney: if isTourney:
pos1 = line.rfind("collected ") + 10 pos1 = line.rfind("collected ") + 10
@ -1035,14 +1035,15 @@ def recognisePlayerIDs(db, names, site_id):
def recognisePlayerNo(line, names, atype): def recognisePlayerNo(line, names, atype):
#print "recogniseplayerno, names:",names #print "recogniseplayerno, names:",names
for i in xrange(len(names)): for i in xrange(len(names)):
encodedName = names[i].encode(LOCALE_ENCODING)
if (atype=="unbet"): if (atype=="unbet"):
if (line.endswith(names[i].encode(encoding))): if (line.endswith(encodedName)):
return (i) return (i)
elif (line.startswith("Dealt to ")): elif (line.startswith("Dealt to ")):
#print "recognisePlayerNo, card precut, line:",line #print "recognisePlayerNo, card precut, line:",line
tmp=line[9:] tmp=line[9:]
#print "recognisePlayerNo, card postcut, tmp:",tmp #print "recognisePlayerNo, card postcut, tmp:",tmp
if (tmp.startswith(names[i].encode(encoding))): if (tmp.startswith(encodedName)):
return (i) return (i)
elif (line.startswith("Seat ")): elif (line.startswith("Seat ")):
if (line.startswith("Seat 10")): if (line.startswith("Seat 10")):
@ -1050,10 +1051,10 @@ def recognisePlayerNo(line, names, atype):
else: else:
tmp=line[8:] tmp=line[8:]
if (tmp.startswith(names[i].encode(encoding))): if (tmp.startswith(encodedName)):
return (i) return (i)
else: else:
if (line.startswith(names[i].encode(encoding))): if (line.startswith(encodedName)):
return (i) return (i)
#if we're here we mustve failed #if we're here we mustve failed
raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype) raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype)