Cusem Posted August 28, 2007 Share Posted August 28, 2007 (edited) Hi all, On the 2+2 fora I saw a Python script to parse Everest Poker handhistory files for usage with GameTime+ (Heads Up Display program for PokerTracker data). The original Everest handhistory files, places you in a random seat, but rotates the table so that you always sit at the bottom. If you are not in Seat 0 in the handhistory files, Gametime+ displays all data at wrong seats. Pomptidom of the 2+2 fora made a Python script to parse the Everest handhistory file and reorder it, so you are always in Seat 0 in order to let gametime+ the right data at the right seat. (script and example handhistory file posted below) I coded a tool to help with little stuff while playing poker (automatic table sorting/skinning and all kinds of simple stuff to make life easier). I'd like to implement a handhistory parser like Pomptidoms but I don't know anything about Python. Is the same thing doable in AutoIT or will it be a major task at what a average/beginning AutoIt fiddler like myself shouldn't start at (at this moment i don't know where to start)? What this script does is monitor the HH's Everest Poker produces, converts them to make sure you are always at seat 0 in the handhistory and writes them in a different directory (output_dir) which you can import into PT. There are 3 settings in this script: - everest_dir: this is the directory where Everest Poker places the handhistories, this is usually correct by default. - output_dir: the directory the script outputs the parsed handhistories, make sure this directory exists. - number_of_players: whether you play headsup (2), shorthanded (6) or fullring (10). Save the code of the script to a .py file (e.g. ConvertEverest.py) and doubleclick to run it. It will not output anything on screen but will parse the handhistories every 60 seconds. Just let it run. Make sure PT imports the output_dir and not the everest_dir. Here's the script:expandcollapse popupimport os, time, re, xml.dom.minidom, xml.parsers.expat ############################### SETTINGS ############################### everest_dir = "C:\Program Files\Everest Poker\history\\" output_dir = "C:\Program Files\Everest Poker\history\processed\\" number_of_players = 6 ############################# / SETTINGS ############################### def ParseFile( filename ): in_file = open( everest_dir + filename, 'rb' ) out_file = open( output_dir + filename, 'wb' ) lines = in_file.readlines() handtext = [ ] for line in lines: handtext.append( line ) if '<SESSION' in line: xmlLine = xml.dom.minidom.parseString( line ) nickname = xmlLine.childNodes[0].getAttribute( 'screenName' ) elif '<HAND' in line: position = { } elif '<SEAT' in line: xmlLine = xml.dom.minidom.parseString( line ) pos = xmlLine.childNodes[0].getAttribute( 'position' ) name = xmlLine.childNodes[0].getAttribute( 'name' ) position[ name ] = pos elif '<DEALER' in line: offset = int( position[ nickname ] ) elif '</HAND>' in line: for l in handtext: try: xmlLine = xml.dom.minidom.parseString( l ) pos = xmlLine.childNodes[0].getAttribute( 'position' ) pos = int(pos) pos = (pos - offset) % number_of_players out_file.write( re.sub( 'position="[0-9]+"', 'position="' + str(pos) + '"', l ) ) except (ValueError, xml.parsers.expat.ExpatError): if '<WIN' in l: pos = int( l[ 17 ] ) pos = (pos - offset) % number_of_players l = l[:17] + str(pos) + l[18:] out_file.write( l ) handtext = [ ] handled = { } while True: files = os.listdir( everest_dir ) for file in files: if re.match( "^[0-9]+\.txt", file ): mtime = os.path.getmtime( everest_dir + file ) if file not in handled: handled[ file ] = 0 if mtime > handled[ file ]: ParseFile( file ) handled[ file ] = mtime time.sleep( 60 ) This is a typical Handhistory file that needs to be parsed. Right now I (Cusem) am in Seat 5, but the complete file has to be rearranged so I am in Seat 0, while keeping the same order (so Seat 6 has to be Seat 1; Seat 7 has to be Seat 2; etc.): <SESSION time="1188253255" tableName="Malabo-0" id="276.35.613" type="ring" money="$" screenName="Cusem" game="hold-em" gametype="no-limit"/> <HAND time="1188253259" id="1997228239" index="0" blinds="$.15/$.25" stakes="$.25/$.25"> <SEAT position="0" name="Empousa" balance="2546"/> <SEAT position="1" name="tjappie81" balance="2385"/> <SEAT position="2" name="@kerstin@" balance="4055"/> <SEAT position="3" name="mathieu07" balance="700"/> <SEAT position="4" name="cornev" balance="1795"/> <SEAT position="5" name="Cusem" balance="2500"/> <SEAT position="6" name="fred3463" balance="5170"/> <SEAT position="7" name="Horstus" balance="2700"/> <SEAT position="8" name="k4l4sh" balance="3010"/> <SEAT position="9" name="Dr-Hugo" balance="1072"/> <DEALER position="0"/> <BLIND position="1" amount="15" penalty="0"/> <BLIND position="2" amount="25" penalty="0"/> <XBLIND position="5"/> <HOLE position="1">--</HOLE> <HOLE position="2">--</HOLE> <HOLE position="3">--</HOLE> <HOLE position="4">--</HOLE> <HOLE position="6">--</HOLE> <HOLE position="7">--</HOLE> <HOLE position="8">--</HOLE> <HOLE position="9">--</HOLE> <HOLE position="0">--</HOLE> <HOLE position="1">--</HOLE> <HOLE position="2">--</HOLE> <HOLE position="3">--</HOLE> <HOLE position="4">--</HOLE> <HOLE position="6">--</HOLE> <HOLE position="7">--</HOLE> <HOLE position="8">--</HOLE> <HOLE position="9">--</HOLE> <HOLE position="0">--</HOLE> <FOLD position="3"/> <FOLD position="4"/> <FOLD position="6"/> <FOLD position="7"/> <BET position="8" amount="25"/> <FOLD position="9"/> <FOLD position="0"/> <BET position="1" amount="10"/> <BET position="2" amount="0"/> <SWEEP rake="0">75</SWEEP> <COMMUNITY>4c, Js, 4d</COMMUNITY> <BET position="1" amount="0"/> <BET position="2" amount="0"/> <BET position="8" amount="25"/> <BET position="1" amount="25"/> <FOLD position="2"/> <SWEEP rake="5">120</SWEEP> <COMMUNITY>10d</COMMUNITY> <BET position="1" amount="100"/> <FOLD position="8"/> <PUSH position="1" amount="100"/> <SWEEP rake="5">120</SWEEP> <XSHOW position="1"/> <WIN position="1" amount="120" pot="0", potAmount="120"/> </HAND> Edited August 28, 2007 by Cusem Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 28, 2007 Share Posted August 28, 2007 Hi, do I get you write that is the part you want to change? <SEAT position="0" name="Empousa" balance="2546"/> <SEAT position="1" name="tjappie81" balance="2385"/> <SEAT position="2" name="@kerstin@" balance="4055"/> <SEAT position="3" name="mathieu07" balance="700"/> <SEAT position="4" name="cornev" balance="1795"/> <SEAT position="5" name="Cusem" balance="2500"/> <SEAT position="6" name="fred3463" balance="5170"/> <SEAT position="7" name="Horstus" balance="2700"/> <SEAT position="8" name="k4l4sh" balance="3010"/> <SEAT position="9" name="Dr-Hugo" balance="1072"/> to <SEAT position="0" name="Cusem" balance="2546"/> <SEAT position="1" name="Empousa" balance="2385"/> <SEAT position="2" name="fred3463" balance="4055"/> <SEAT position="3" name="Horstus" balance="700"/> <SEAT position="4" name="k4l4sh" balance="1795"/> <SEAT position="5" name="Dr-Hugo" balance="2500"/> <SEAT position="6" name="tjappie81" balance="5170"/> <SEAT position="7" name="@kerstin@" balance="2700"/> <SEAT position="8" name="mathieu07" balance="3010"/> <SEAT position="9" name="cornev" balance="1072"/> ??? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Cusem Posted August 28, 2007 Author Share Posted August 28, 2007 Well, I guess every [ position="?" ] has to be changed (every ? has to be changed), otherwise the values don't match. At first I thought the lines had to be reordered as well, but fortunately enough that is not the case. The only thing that are to be changed are the values of the positions. Meanwhile I'm googeling and searching the forum (more intensive than I did) and I guess it should be done with StringRegExp and StringRegExpReplace. I don't know anything about these commands, so I'm reading the helpfile about it. Not the easiest commands I guess. Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 28, 2007 Share Posted August 28, 2007 HI, show us before and after the change and I 'll help you with the regex to change it. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Cusem Posted August 28, 2007 Author Share Posted August 28, 2007 Sorry for bothering you all. It was easier than I thought and managed to fix it myself. This is the result: (I'm sure coding could be much more efficient, but I'm not a AutoIt expert and I'm always happy if something works) expandcollapse popup;testvariables $parsechk = 1 $maxplayers = 10 Opt("TrayIcondebug",1) #include <file.au3> $hh_everestpath = "C:\Program Files (x86)\Everest Poker\history\" $hh_outputpath = "C:\Program Files (x86)\Everest Poker\historyparsed\" $hh_backuppath = "C:\Program Files (x86)\Everest Poker\historyparsed\BackupHH" $parsetimeout = 2500 $search = FileFindFirstFile($hh_everestpath & "*.*") $hh_file = FileFindNextFile($search) $lines = _FileCountLines($hh_everestpath&$hh_file) ;===>>> Get ScreenName $screenname = "" $hh_in = FileOpen($hh_everestpath&$hh_file,0) For $a = 1 to $lines $line = FileReadline($hh_in) $result = StringInStr($line, "screenName", 1, 1) If $result <> 0 Then $screenname = StringMid($line, $result + 12, 45) $stoppos = StringInStr($screenname, Chr(34), 0, 1) $screenname = StringTrimRight($screenname, 44 - $stoppos) EndIf Next FileClose($hh_in) ;===>>> Get Seat Position $offset = 0 $hh_in = FileOpen($hh_everestpath&$hh_file,0) For $a = 1 to $lines $line = FileReadline($hh_in) $result = StringInStr($line, $screenname & Chr(34) & " balance", 1, 1) If $result <> 0 Then $offset = Int(StringMid($line, 19, 1)) EndIf Next FileClose($hh_in) ;===>>> FileParsing $hh_in = FileOpen($hh_everestpath&$hh_file,0) $hh_out = FileOpen($hh_outputpath&$hh_file,1) For $a = 1 to $lines $line = FileReadLine($hh_in) $replace = StringInStr($line, "position=", 1, 1) If $replace <> 0 Then $seat = Int(StringMid($line, $replace + 10, 1)) $seat = $seat - $offset If $seat < 0 Then $seat = $seat + $maxplayers $line = StringReplace($line, $replace + 10, $seat, 1, 1) EndIf FileWriteLine($hh_out, $line) Next FileClose($hh_in) FileClose($hh_out) FileMove($hh_everestpath&$hh_file, $hh_backuppath, 1) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now