Skip to content

Instantly share code, notes, and snippets.

@ryandgoldenberg1
Created May 31, 2015 22:07
Show Gist options
  • Save ryandgoldenberg1/30b6341fbe79fb4e5c18 to your computer and use it in GitHub Desktop.
Save ryandgoldenberg1/30b6341fbe79fb4e5c18 to your computer and use it in GitHub Desktop.
Takes a file of USCF IDs and outputs a file of USCF ratings
require 'open-uri'
# first argument: file containing uscf id numbers
# second argument: file you wish to write ratings to
if ARGV.length < 2 then return nil end
# gets unofficial rating
def get_rating(id)
# opens page for corresponding to id number
f = open("http://www.uschess.org/msa/MbrDtlTnmtHst.php?#{id}")
# skips to relevant info and then grabs rating
(0...118).each {|i| f.readline}
rating = f.readline.scan(/<b>\d+/)[0].scan(/\d+/)[0].to_i
f.close
return rating
end
file_name = ARGV[0]
f = open(file_name, 'r')
g = open(ARGV[1], 'w')
f.each {|l|
rating = get_rating(l)
g.write("#{rating}\n")
}
f.close
g.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment