Merge branch 'master' of git://github.com/grindi/fpdb-grindi

This commit is contained in:
Worros 2009-08-15 19:06:39 +08:00
commit dede86521a
5 changed files with 100 additions and 114 deletions

View File

@ -29,7 +29,7 @@ class Fulltilt(HandHistoryConverter):
sitename = "Fulltilt"
filetype = "text"
codepage = "cp1252"
codepage = "utf-16"
siteId = 1 # Needs to match id entry in Sites database
# Static regexes
@ -135,24 +135,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
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):
m = self.re_HandInfo.search(hand.handText)
if(m == None):

View File

@ -302,14 +302,13 @@ If a player has None chips he won't be added."""
return c
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:
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)
act = (player, 'posts', "ante", ante, self.stacks[player]==0)
self.actions['ANTES'].append(act)
#~ self.lastBet['ANTES'] = Decimal(ante)
self.actions['BLINDSANTES'].append(act)
self.pot.addMoney(player, Decimal(ante))
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))
if player is not None:
amount = re.sub(u',', u'', amount) #some sites have commas
self.bets['PREFLOP'][player].append(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)
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))
if blindtype == 'big blind':
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]]
#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).
Card ranks will be uppercased
"""
import sys; sys.exit(1)
log.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard))
if cards is not None:
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 ''))
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 ''))
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':
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':
@ -621,6 +623,7 @@ class HoldemOmahaHand(Hand):
hhc.compilePlayerRegexs(self)
hhc.markStreets(self)
hhc.readBlinds(self)
hhc.readAntes(self)
hhc.readButton(self)
hhc.readHeroCards(self)
hhc.readShowdownActions(self)
@ -885,6 +888,7 @@ class DrawHand(Hand):
hhc.compilePlayerRegexs(self)
hhc.markStreets(self)
hhc.readBlinds(self)
hhc.readAntes(self)
hhc.readButton(self)
hhc.readHeroCards(self)
hhc.readShowdownActions(self)
@ -1042,11 +1046,11 @@ class StudHand(Hand):
if gametype['base'] != 'stud':
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.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']
Hand.__init__(self, sitename, gametype, handText)
self.sb = gametype['sb']
@ -1064,7 +1068,7 @@ class StudHand(Hand):
hhc.readHeroCards(self)
# Read actions in street order
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]:
log.debug(street + self.streets[street])
hhc.readAction(self, street)
@ -1153,14 +1157,14 @@ Add a complete on [street] by [player] to [amountTo]
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]:
#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]))
if 'ANTES' in self.actions:
for act in self.actions['ANTES']:
if 'BLINDSANTES' in self.actions:
for act in self.actions['BLINDSANTES']:
print >>fh, _("%s: posts the ante %s%s" %(act[0], self.sym, act[3]))
if 'THIRD' in self.actions:
@ -1308,6 +1312,7 @@ class Pot(object):
self.contenders = set()
self.committed = {}
self.streettotals = {}
self.common = Decimal(0)
self.total = None
self.returned = {}
self.sym = u'$' # this is the default currency symbol
@ -1322,13 +1327,16 @@ class Pot(object):
# addFold must be called when a player folds
self.contenders.discard(player)
def addCommonMoney(self, amount):
self.common += amount
def addMoney(self, player, amount):
# addMoney must be called for any actions that put money in the pot, in the order they occur
self.contenders.add(player)
self.committed[player] += amount
def markTotal(self, street):
self.streettotals[street] = sum(self.committed.values())
self.streettotals[street] = sum(self.committed.values()) + self.common
def getTotalAtStreet(self, street):
if street in self.streettotals:
@ -1336,7 +1344,7 @@ class Pot(object):
return 0
def end(self):
self.total = sum(self.committed.values())
self.total = sum(self.committed.values()) + self.common
# Return any uncalled bet.
committed = sorted([ (v,k) for (k,v) in self.committed.items()])

View File

@ -39,6 +39,7 @@ if os.name == 'nt':
# FreePokerTools modules
import Configuration
from fpdb_simple import LOCALE_ENCODING
# 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
@ -231,19 +232,12 @@ def discover_nt_by_name(c, tablename):
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:
#print "Tables.py: tablename =", tablename, "title =", titles[hwnd]
try:
# 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
if not tablename.lower() in titles[hwnd].decode(getDefaultEncoding()).lower(): continue
if not tablename.lower() in titles[hwnd].decode(LOCALE_ENCODING).lower(): continue
except:
continue
if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window

View File

@ -380,8 +380,9 @@ class Importer:
conv = None
(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:
print "\nConverting " + file + " (" + str(q.qsize()) + ")"
else:

View File

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