Skip to content
Browse files

Fix a bug with no played games at some days

  • Loading branch information...
1 parent 6da832f commit c076f1bce45f6ff7ebf9e2a9cc94a3e37a4f67b7 @sharipov-ru sharipov-ru committed
Showing with 24 additions and 17 deletions.
  1. +24 −17 espn_nhl_parser.rb
View
41 espn_nhl_parser.rb
@@ -3,23 +3,30 @@
require 'open-uri'
games = []
-url = "http://espn.go.com/nhl/scoreboard"
+url = "http://espn.go.com/nhl/scoreboard?date=20110402"
doc = Nokogiri::HTML(open(url))
+
doc.css("div.game-header").each do |gametable| # gametable - html table of current game
- loser = gametable.at_css("tr.loser a").text
- winner = gametable.at_css("tr.winner a").text
- winner_place = gametable.at_css("tr.winner")[:id].scan(/home|away/)
- score = []
- gametable.css("td.team-score").each do |team_score| # Need to find two scores per game (for away and home teams)
- score << team_score.text
- end
- result = "#{score[1]}:#{score[0]}" # Away team - Home team
- if winner_place.to_s == "home"
- game = "#{winner}-#{loser} #{result}"
- else
- game = "#{loser}-#{winner} #{result}"
- end
- games << game
-end
+ unless gametable.at_css("tr.loser a").nil? # if game not started
+ loser = gametable.at_css("tr.loser a").text
+ winner = gametable.at_css("tr.winner a").text
+ winner_place = gametable.at_css("tr.winner")[:id].scan(/home|away/)
+ score = []
+ gametable.css("td.team-score").each do |team_score| # Need to find two scores per game (for away and home teams)
+ score << team_score.text
+ end
+ result = "#{score[1]}:#{score[0]}" # Away team - Home team
+ if winner_place.to_s == "home"
+ game = "#{winner}-#{loser} #{result}"
+ else
+ game = "#{loser}-#{winner} #{result}"
+ 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.
Something went wrong with that request. Please try again.