Webサイトの更新を逐一知るためのスクリプト

Program & Service

概要

  • Rubyを仕事で書き始めて1ヶ月半が経過しました。
  • ほんと、gemのおかげで書くコードが少なくて大変助かっております。
  • ということで、そのgemに貢献するためにも、ある程度汎用性のある機能が出来たらgem作っていこうと思っています。

作ったもの

gem

使い方

Installation

Add this line to your application’s Gemfile:

gem 'web_update_checker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install web_update_checker

Usage

main.rb

regex = /<h1>(.*)<\/h1>/

mail = Mail.new do
from    '[email protected]'
to      '[email protected]'
subject 'Web site is updated!'
body     @url
end

mail.delivery_method :smtp, {
address:   'localhost',
             port:      25,
}

url = 'http://example.com/'
WebUpdateChecker::Checker.new(url, regex, mail).execute

Execute like a following CLI

% while [ true ]; do; ruby main.rb; sleep 30; done

コメント