collect Golf's World Rankings on your own with new Ruby module!
You can find the code on GitHub at the links above....Official Golf World Ranking, OGWR...
wrote some Ruby code in a Module that grabs the official golf world rankings...
use the data as you wish in your own application...
released as open source...enables anyone to take the active OGWR data and do with it what you wish
(E.g. store to a database each week, hold in your database to related to players on your website, etc).
...it's decent for a start, planning on continuing to make it more versatile and useful...
This file contains 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
#!/usr/bin/env ruby -w | |
# created by Mark Holton (holtonma@gmail.com) | |
# copy as much as you want to | |
# 10-29-2008 | |
# purpose: scrape the official world golf ranking, and present it in a more | |
# usable form (Array of ostruct's) | |
# using Hpricot, open-uri | |
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
require 'ostruct' | |
module OGWR | |
VERSION = '0.1.0' | |
class PageFetcher | |
def fetch(ogwr_url, page_num) | |
#page_num indicates range of 50n: page 1 >> 1-50, page 2 >> 51-100, page 3 >> 101-150... | |
data = Hpricot(open(ogwr_url)).search("table:nth-child(5)") | |
players = [] #init | |
start_rank = -1 + 50*(page_num-1) #(there are 2 empty trs to start the world ranking) #instead of a counter, I should extract this from page | |
(data/"td:nth-child(2)").each do |x| | |
playa = OpenStruct.new | |
playa.fname = x.search("a").inner_html.split(" ")[0] | |
playa.lname = x.search("a").inner_html.split(" ")[1] | |
playa.rank = start_rank | |
puts "#{playa.fname} #{playa.lname} #{playa.rank}" | |
players << playa | |
start_rank += 1 | |
end | |
#clean this line up: | |
players.pop; players.reverse!; players.pop; players.pop; players.reverse! #remove one extra row at end, 2 extra at beginning | |
players | |
end | |
end | |
end |
2 comments:
Good sharing of this nice post.
hermes belt
Wonderful job. Thanks for sharing such a good post.
black birkin bag
Post a Comment