Skip to content

Instantly share code, notes, and snippets.

@haqu
Created May 17, 2011 04:01
Show Gist options
  • Save haqu/975928 to your computer and use it in GitHub Desktop.
Save haqu/975928 to your computer and use it in GitHub Desktop.
Getting number of votes and coolness from Ludum Dare ratings page
#!/usr/bin/env ruby -wKU
# if you don't want to provide your username each time
# as an argument, you can set it here:
user = "" # <-- your username
# default stat to compare: votes or coolness
compare = "votes" # or "coolness"
######################################################
require 'open-uri'
user = ARGV.shift if user.empty?
if not user
puts
puts "usage: #{$0} username [votes|coolness]"
puts
exit
end
compare = ARGV.shift if not ARGV.empty?
puts
puts "Getting number of votes and coolness from Ludum Dare ratings page"
puts "and calculating current position based on the \"#{compare}\" stat."
puts
statsURL = "http://www.ludumdare.com/compo/ludum-dare-20/?action=misc_links"
content = open(statsURL).read
users = {}
content.scan(/a><td>(.+?)<td><a.+?<td>(\d+)<td>(\d+)<t/m).each do |u,v,c|
users[u] = { :votes => v, :coolness =>c }
end
if not users[user]
puts "user \"#{user}\" not found"
puts
exit
end
t = compare == "votes" ? :votes : :coolness
sorted = users.sort do |u1,u2|
u1[1][t].to_i <=> u2[1][t].to_i
end
sorted.reverse!
pos = 1
sorted.each do |u,vc|
puts if u == user
puts "%3d. %s (%d:%d)" % [pos, u, vc[:votes], vc[:coolness]]
break if u == user
pos += 1
end
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment