Skip to content
This repository

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 123 lines (114 sloc) 3.114 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
#!/usr/bin/ruby
require "getoptlong"

def display(playername, players_shown = {})
  return if players_shown[playername]
  puts "=" * 90
  puts "Reading Poker-Edge Data for '#{playername}'... "
  puts "-" * 90
  result = `curl -s http://www.poker-edge.com/whoami.php?name='#{playername.gsub(/ /, "%20")}'`
  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 doftfile(file, players_shown)
  puts "doing ftfile #{file}"
  return if File.directory?(file)
  players = []
  game = nil
  state = :waiting_for_new_game
  file = File.open(file, "r").each do |line|
    case state
    when :waiting_for_new_game
      if line =~ /Full Tilt Poker Game #([0-9]+)/
        players = []
        game = line
        state = :collecting_players
      end
    when :collecting_players
      if line =~ /Seat [1-9]: ([^(]+) \(/
        players << $1
      else
        state = :waiting_for_new_game
      end
    end
  end
  puts
  puts "=" * 90
  puts game
  players.each {|each| display(each, players_shown)}
  puts
  puts "=" * 75
  puts "PLAYERS NOW AT THIS TABLE"
  puts "=" * 75
  players.each do |each|
    puts "#{each}: #{players_shown[each]}"
  end
  puts "=" * 90
  puts
end

# def newftfiles(user, player, time)
# Dir["/Users/#{user}/Documents/HandHistory/#{player}/*"].select{|each| File.mtime(each) > time}
# end
#
def newftfiles(user, time)
  Dir["/Users/#{user}/Documents/HandHistory/**/*"].select{|each| File.mtime(each) > time}
end


def getftdata(user, time, players_shown)
  puts "Loading Full Tilt hands since #{time}"
  while (files = newftfiles(user, time)).empty?
    sleep 1
  end
  files.each {|each| doftfile(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, version 0.3\n"
  when "--user"
    user = arg unless arg.empty?
  when "--player"
    player = arg unless arg.empty?
  end
end

players_shown = {}
loop {getftdata(user, Time.now, players_shown)} if $*.empty?
$*.each do |playername|
  display(playername)
end
Something went wrong with that request. Please try again.