Skip to content

Commit

Permalink
Fix a bug with no played games at some days
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharipov Ruslan committed Apr 4, 2011
1 parent 6da832f commit c076f1b
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions espn_nhl_parser.rb
Expand Up @@ -3,23 +3,30 @@
require 'open-uri' require 'open-uri'


games = [] games = []
url = "http://espn.go.com/nhl/scoreboard" url = "http://espn.go.com/nhl/scoreboard?date=20110402"
doc = Nokogiri::HTML(open(url)) doc = Nokogiri::HTML(open(url))

doc.css("div.game-header").each do |gametable| # gametable - html table of current game doc.css("div.game-header").each do |gametable| # gametable - html table of current game
loser = gametable.at_css("tr.loser a").text unless gametable.at_css("tr.loser a").nil? # if game not started
winner = gametable.at_css("tr.winner a").text loser = gametable.at_css("tr.loser a").text
winner_place = gametable.at_css("tr.winner")[:id].scan(/home|away/) winner = gametable.at_css("tr.winner a").text
score = [] winner_place = gametable.at_css("tr.winner")[:id].scan(/home|away/)
gametable.css("td.team-score").each do |team_score| # Need to find two scores per game (for away and home teams) score = []
score << team_score.text gametable.css("td.team-score").each do |team_score| # Need to find two scores per game (for away and home teams)
end score << team_score.text
result = "#{score[1]}:#{score[0]}" # Away team - Home team end
if winner_place.to_s == "home" result = "#{score[1]}:#{score[0]}" # Away team - Home team
game = "#{winner}-#{loser} #{result}" if winner_place.to_s == "home"
else game = "#{winner}-#{loser} #{result}"
game = "#{loser}-#{winner} #{result}" else
end game = "#{loser}-#{winner} #{result}"
games << game end
end games << game
end # unless`
end # each


puts games if games.empty?
puts "Today no played games"
else
puts games
end

0 comments on commit c076f1b

Please sign in to comment.