Skip to content

Instantly share code, notes, and snippets.

@saboyutaka
Created November 5, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saboyutaka/8b8882d14661b3364e97ee1dbb417a94 to your computer and use it in GitHub Desktop.
Save saboyutaka/8b8882d14661b3364e97ee1dbb417a94 to your computer and use it in GitHub Desktop.
#!/usr/bin/env /Users/yutaka/.rbenv/shims/ruby
ENV['PATH'] += ':/usr/local/bin'
require 'capybara/poltergeist'
require 'date'
require 'open3'
require 'dotenv'
Dotenv.load File.expand_path('../.env', __FILE__)
puts ':tennis:'
puts '---'
puts 'Service Ace | href=https://okinawa.lan.jp/web/login.php?'
puts '---'
o, e, s = Open3.capture3("ifconfig | grep 'status: active'")
if !o.empty?
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {:js_errors => false, :timeout => 1000 })
end
s = Capybara::Session.new(:poltergeist)
s.visit 'https://okinawa.lan.jp/web/login.php?'
s.find('input[name=f_codeno]').set(ENV['SERVICE_ACE_ID'])
s.find('input[name=f_password]').set(ENV['SERVICE_ACE_PASS'])
s.find('input[name=f_submit]').click
(Date.today..(Date.today + 2)).each do |date|
next if date.sunday?
s.visit('https://okinawa.lan.jp/web/reserv/reserv_date.php')
s.execute_script("go_next('#{date}')")
if s.html.include? 'ログインしてください。'
puts 'セッションが有効期限切れになりました。'
break
end
d = s.find('#content2 > table > tbody > tr:nth-of-type(2) > td > form > table > tbody > tr > td > table:nth-of-type(2) > tbody > tr > td:nth-of-type(2)').text
puts "#{d} | color=black"
s.find_all('#content2 > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr > td > table:nth-of-type(3) > tbody > tr')[1..-1].each do |lesson|
_klass, time, rank, attendies, coat, coach, _reserve = lesson.text.split
rank = rank.split(':').last
attendies = 10 - attendies.scan(/\d+/)[0].to_i rescue '?'
output = [time, rank, attendies, coat, coach].join(" ")
puts "#{output} | color=black"
end
puts '---'
end
else
puts 'No Network'
end
puts 'Refresh... | refresh=true'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment