Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#-*- coding: euc-jp -*-
require 'rubygems'
require 'mechanize'
require 'kconv'
require "./tlsmails.rb"
class NoLectureInformation
def initialize(h={})
@h = h
unless h.key?(:date) && h.key?(:time) \
&& h.key?(:place) && h.key?(:name) \
&& h.key?(:lecturer) && h.key?(:note)
raise ArgumentError, "needs date,time,place,name,lectureer,note"
end
h.each do |k,v|
# raise ArgumentError, "Should kind of String" unless v.kind_of?(String)
eval "@#{k} = #{v.inspect}"
end
end
def inspect
@h.inspect
end
attr_reader :date, :time, :place, :name, :lecturer, :note
end
agent = Mechanize.new
agent.get('https://login.keio.jp/koid/')
agent.page.form_with(:action => 'login') do |form|
form.field_with(:name => 'SignOnID').value = "your keio.jp ID"
form.field_with(:name => 'Passwd').value = "your keio.jp Password"
form.click_button
end
agent.page.form_with(:action => 'https://www2.adst.keio.ac.jp/rishu/servlet/jp.ac.keio.ess.adst.servlet.view.PortalAuthenticateServlet') do |form|
form.click_button
end
agent.page.form_with(:action => '../servlet/jp.ac.keio.ess.adst.servlet.view.GakujiTopMenuServlet?param=adst') do |form|
form.click_button(form.button_with(:name => 'ATM001PbNoLectureCheck'))
end
agent.page.form_with(:action => '../servlet/jp.ac.keio.ess.adst.servlet.view.NoLectureCheckServlet?param=adst') do |form|
form.radiobutton_with(:value => '2',:name => 'ALC001RbSelect1').check
form.radiobutton_with(:value => '2',:name => 'ALC001RbSelect2').check
form.click_button
end
r = agent.page.search('tr.ResultItems>td>table').inner_text.toeuc
abort "Lectures are going to done normally" if r.include?("休講情報はありません")
is = agent.page.search('tr.ResultItems>td>table>tr')
nris = []
is.each do |i|
attrs = i.search('td').map{|x|x.inner_text.toeuc }
break if attrs.size == 8
nris << NoLectureInformation.new(
:date => attrs[0],
:time => attrs[1],
:place => attrs[2],
:name => attrs[3],
:lecturer => attrs[4],
:note => attrs[5]
)
end
s = nris[0..-2].map do |n|
"日時:#{n.date}\n曜時:#{n.time}\n地区:#{n.place}\n科目名:#{n.name}\n担当者:#{n.lecturer}\n備考:#{n.note}"
end.join("\n\n")
puts s
sendgmail("from@hoge.com",%w{to@hoge.com}, "休講情報", <<EOT)
#{s}
EOT
# encoding: euc-jp
require "rubygems"
require "tlsmail"
require "net/smtp"
def sendgmail(from, to, subject, body, user = "your Gmail account", pass = "your Gmail pass", host = "smtp.gmail.com", port = 587)
body = <<EOT
From: #{from}
To: #{to.to_a.join(",\n ")}
Subject: #{subject}
Date: #{Time::now.strftime("%a, %d %b %Y %X %z")}
Mime-Version: 1.0
Content-Type: text/plain; charset=EUC-JP
Content-Transfer-Encoding: 7bit
#{body}
EOT
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start(host, port, "localhost.localdomain", user, pass, "plain") do |smtp|
smtp.send_mail body, from, to
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.