Last active
December 16, 2015 11:09
-
-
Save pdfrod/5425666 to your computer and use it in GitHub Desktop.
Scrapes the list of contestants in Portugal from the Google Code Jam 2013 Qualification Round
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'json' | |
MAXPOS = 21261 | |
STEP = 20 | |
def getUrl(pos) | |
"http://code.google.com/codejam/contest/2270488/scoreboard/do/?cmd=GetScoreboard&start_pos=#{pos}" | |
end | |
contestants = (1..MAXPOS).step(STEP).flat_map do |i| | |
$stderr.puts "Reading page #{i}" | |
open(getUrl(i)) do |f| | |
json = JSON.parse(f.read) | |
json['rows'].find_all {|row| row['c'] == 'Portugal'} | |
end | |
end | |
contestants.each do |c| | |
puts "#{c['r']} #{c['n']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment