Created
October 6, 2009 00:24
-
-
Save brianleroux/202644 to your computer and use it in GitHub Desktop.
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
%w(rubygems hpricot open-uri json).each { |x| require x } | |
doc = Hpricot.parse(open("http://www.nhl.com/schedules/20092010.html#?navid=nav-sch-sea")) | |
data = (doc/'div[@class=skedDataRow]') | |
def parse_game_date(e) | |
(e/'div[@class=skedDataRow date]').innerHTML.gsub(' ',' ').strip | |
end | |
def parse_game_time(e) | |
(e/'div[@id=skedStartTimeLocal]').innerHTML.strip | |
end | |
def parse_visiting_team(e) | |
(e/'div[@class=skedDataRow team]'/'div'/'a')[0].innerText.strip | |
end | |
def parse_home_team(e) | |
(e/'div[@class=skedDataRow team]')[1].innerText.strip | |
end | |
def parse_network(e) | |
(e/'div[@class=skedDataRow network]').innerHTML.strip | |
end | |
# lets clean this shit up | |
fresh = [] | |
data.each do |e| | |
game_date = parse_game_date(e) | |
game_time = parse_game_time(e) | |
visting_team = parse_visiting_team(e) | |
home_team = parse_home_team(e) | |
network = parse_network(e) | |
fresh << [game_date, game_time, visting_team, home_team, network] | |
end | |
File.open(File.join(File.dirname(__FILE__), 'nhl.json'),'w') {|f| f << fresh.to_json } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment