Created
July 10, 2016 13:32
-
-
Save kawakubox/e316eb395fa7c00ada3de09db066a050 to your computer and use it in GitHub Desktop.
Bitbarでプロ野球の試合経過を表示するrubyスクリプト
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 /Users/kawakubox/.rbenv/shims/ruby | |
require 'httpclient' | |
require 'oga' | |
client = HTTPClient.new | |
res = client.get('http://baseball.yahoo.co.jp/npb/') | |
puts '⚾' | |
puts '---' | |
doc = Oga.parse_html(res.body) | |
doc.css('#NpbBoxTeam table.teams').each do |game| | |
teams = game.css('tr th').map { |team| team.at_css('a').attr('title').value } | |
scores = game.css('table.score td.score_r').map(&:text) | |
inning = game.at_css('table.score tr:nth-of-type(2) a').text | |
puts "#{inning} #{teams[0]} #{scores[0]} - #{scores[1]} #{teams[1]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment