Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 163 lines (152 sloc) 4.98 kb
#!/usr/bin/ruby
require "getoptlong"
require "Time"
require "uri"
require File.expand_path(File.dirname(__FILE__) + "/PSFile.rb")
def display(playername, players_shown = {})
return if players_shown[playername]
puts "=" * 90
puts "Reading Poker-Edge Data for '#{playername}'... "
puts "-" * 90
puts escaped_playername = URI.escape(playername).gsub(/["']/,'\\\\\&')
result = `curl -s http://www.poker-edge.com/whoami.php?name=#{escaped_playername}&site=Stars`
puts "Results for #{playername}:"
if result =~ /(Pre-Flop Tend.*\n)/
verbose = $1.gsub(/<\/?[^>]*>/, "")
if verbose =~ /Pre-Flop Tendency: ([^-]*) -/
preflop = $1
else
preflop = "N/A"
end
puts verbose
else
puts "could not get data for this player"
puts "=" * 90
next
end
if result =~ /(Player Type.*\n)/
verbose = $1.gsub(/<\/?[^>]*>/, "")
if verbose =~ /[Yy]ou are a ([^(]* \(.*\))/
player_type = $1
else
player_type = ""
end
puts verbose
else
puts "could not get type data for this player"
puts "=" * 90
next
end
puts "=" * 90
players_shown[playername] = preflop
players_shown[playername] += " " + player_type unless player_type.empty?
end
def dopsfile(file, players_shown)
puts "doing psfile #{file}"
return if File.directory?(file)
this = nil
hands = {}
vpip = {}
pfr = {}
sawflop = {}
preflop_aggressive = {}
postflop_aggressive = {}
preflop_passive = {}
postflop_passive = {}
last = nil
PSFile.open(file).each do |handrecord|
# puts handrecord.lines
last = handrecord
next if handrecord.players.nil?
handrecord.players.each do |player|
hands[player] ||= 0
hands[player]+=1
vpip[player] ||= 0
vpip[player]+=1 if handrecord.vpip? player
pfr[player] ||= 0
pfr[player]+=1 if handrecord.pfr? player
sawflop[player] ||= 0
sawflop[player]+=1 if handrecord.sawflop? player
preflop_aggressive[player] ||= 0
preflop_aggressive[player]+= handrecord.preflop_aggressive player
preflop_passive[player] ||= 0
preflop_passive[player]+= handrecord.preflop_passive player
postflop_aggressive[player] ||= 0
postflop_aggressive[player]+= handrecord.postflop_aggressive player
postflop_passive[player] ||= 0
postflop_passive[player]+= handrecord.postflop_passive player
end
end
return if last.nil?
players = last.players
return if players.nil?
puts
puts "=" * 90
puts last.game
players.each {|each| display(each, players_shown)}
puts
puts "=" * 90
puts "PLAYERS NOW AT THIS TABLE"
puts "=" * 90
printf "%-20s %3s %4s %4s %5s %s\n", "Screen Name", "Num", "VP$%", "PFR%", "Pre/Pos", "Poker-Edge Description"
printf "%-20s %-14s %s\n", "-"*20, "-"*21, "-"*47
players.each do |each|
description = players_shown[each][/\(.*\)/]
description ||= ""
description.gsub!("Passive", "P")
description.gsub!("Aggressive", "A")
description.gsub!("Tight", "T")
description.gsub!("Loose", "L")
players_shown[each].gsub!(/\(.*\)/, description)
printf "%-20s %3d %3d%% %3d%% %2.1f/%2.1f %s\n", each,
hands[each], (100.0 * vpip[each])/hands[each], (100.0 * pfr[each])/hands[each],
preflop_passive[each].zero? ? 0.0 : (1.0 * preflop_aggressive[each]) / preflop_passive[each],
postflop_passive[each].zero? ? 0.0 : (1.0 * postflop_aggressive[each]) / postflop_passive[each],
players_shown[each]
end
puts "=" * 90
puts "information on #{hands.size} players collected"
hands = vpip = pfr = sawflop = preflop_aggressive = preflop_passive = nil
GC.start
puts
end
# def newpsfiles(user, player, time)
# Dir["/Users/#{user}/Documents/HandHistory/#{player}/*"].select{|each| File.mtime(each) > time}
# end
#
def newpsfiles(user, time)
# puts "newpsfiles(#{user}, #{time})"
Dir["/Users/#{user}/Library/Application Support/PokerStars/HandHistory/**/*"].select{|each| File.mtime(each) > time}
end
def getpsdata(user, time, players_shown)
puts "Loading PokerStars hands since #{time}"
while (files = newpsfiles(user, time)).empty?
sleep 1
end
files.each {|each| dopsfile(each, players_shown)}
end
opts = GetoptLong.new(
[ "--help", "-h", GetoptLong::NO_ARGUMENT],
[ "--version", "-v", GetoptLong::NO_ARGUMENT],
[ "--user", "-u", GetoptLong::OPTIONAL_ARGUMENT],
[ "--player", "-p", GetoptLong::OPTIONAL_ARGUMENT]
)
user = `whoami`.chop
player = "wizardwerdna"
opts.each do |opt, arg|
case opt
when "--help", "--usage"
print "#{$0} playername {--user username} {--player playername} {--help } {--version}\n"
when "--version"
print "Judi's Awesome Poker Program -- for PokerStars, version 0.6\n"
when "--user"
user = arg unless arg.empty?
when "--player"
player = arg unless arg.empty?
end
end
players_shown = {}
loop {getpsdata(user, Time.now, players_shown)} if $*.empty?
$*.each do |playername|
display(playername)
end
Jump to Line
Something went wrong with that request. Please try again.