239 文字
1 分
Webサイトの更新を逐一知るためのスクリプト
概要
- Rubyを仕事で書き始めて1ヶ月半が経過しました。
- ほんと、gemのおかげで書くコードが少なくて大変助かっております。
- ということで、そのgemに貢献するためにも、ある程度汎用性のある機能が出来たらgem作っていこうと思っています。
作ったもの
- まず、第1弾として、Webサイトチェッカーを作りました。
- あるページが更新されたあとすぐに更新を知るためのスクリプトです。
- ソースコード
- gemの作成に関してはこちらのサイト通りに作れば問題無かったです。

使い方
Installation
Add this line to your application’s Gemfile:
gem 'web_update_checker'And then execute:
$ bundleOr install it yourself as:
$ gem install web_update_checkerUsage
main.rb
regex = /<h1>(.*)<\/h1>/
mail = Mail.new dofrom '[email protected]'to '[email protected]'subject 'Web site is updated!'body @urlend
mail.delivery_method :smtp, {address: 'localhost', port: 25,}
url = 'http://example.com/'WebUpdateChecker::Checker.new(url, regex, mail).executeExecute like a following CLI
% while [ true ]; do; ruby main.rb; sleep 30; done Webサイトの更新を逐一知るためのスクリプト
https://blog.teraren.com/posts/gem/