dotfiles/bin/jytecheck
michener 83d40113d2 First import
git-svn-id: http://photonzero.com/dotfiles/trunk@1 23f722f6-122a-0410-8cef-c75bd312dd78
2007-03-19 06:17:17 +00:00

46 lines
1 KiB
Ruby
Executable file

#!/usr/bin/ruby
require 'net/http'
require 'getoptlong'
class JyteEntry
def initialize(vfor, vagainst, title)
@vfor = vfor
@vagainst = vagainst
@title = title
end
def print
printf "[\033[32m#@vfor\033[0m "
printf "\033[31m#@vagainst\033[0m]\t"
printf "#@title\n"
end
end
opts = GetoptLong.new(
["--number", "-n", GetoptLong::REQUIRED_ARGUMENT]
)
donum = 10
opts.each do |opt, arg|
if opt == "-n" or opt == "--number"
donum = arg.to_i
end
end
donuma = (donum / 10.0).ceil
jytes = Array.new()
1.upto(donuma) do |num|
response = Net::HTTP.start("jyte.com").post("/claims", "page=#{num}")
titles = (response.body.scan(%r{a class=\"claim_title\"\n\s*href=\"http:(.*?)\">\n\s*(.*?)\n\s*</a>}m))
votesfor = (response.body.scan(%r{votes_left_text_\d*\" style=\"color:#fff;\">(.*?)</span>}m))
votesagainst = (response.body.scan(%r{votes_right_text_\d*\" style=\"color:#fff;\">(.*?)</span>}m))
0.upto(9) do |i|
jytes.push(JyteEntry.new(votesfor[i][0],votesagainst[i][0],titles[i][1]))
end
end
0.upto(donum - 1) {|x| jytes[x].print}