Skip to content

Instantly share code, notes, and snippets.

@kawakubox
Created July 10, 2016 13:32
Show Gist options
  • Save kawakubox/e316eb395fa7c00ada3de09db066a050 to your computer and use it in GitHub Desktop.
Save kawakubox/e316eb395fa7c00ada3de09db066a050 to your computer and use it in GitHub Desktop.
Bitbarでプロ野球の試合経過を表示するrubyスクリプト
#!/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