五月雨
ダウンロード
以下から CVS 版の tarball を取得してください
http://cvs.m17n.org/viewcvs/ruby/samidare/
プログラム本体の他に、
が必要です。yaml4r は ruby 1.8 以降では標準添付ライブラリです。
Debian での導入
samidare のパッケージがあるので apt-get install してください。
動作例
http://yoosee.net/a/ で五月雨を利用した更新時刻取得サイトを運用しています。
設定ファイルの例
- t.latest.html : HTree Template 形式で記述された出力ファイル用テンプレート
- config.yml : yaml で記述された設定ファイル
設定
samidareの設定
プログラム本体内を変更する必要は基本的にはありません。実行時オプションを参考ください。
テンプレートファイルの設定(htree形式)
設定ファイルは標準では t.latest.html で、これから latest.html が生成されます。形式は XML/XHTML ですが、htree のルールに従って記述することができます。Template ファイルは -T オプションで指定できます。また出力ファイル名を latest.html 以外にする場合は --output='filename' オプションが利用出来ます( -o option は恐らく bug のため現在は利用できません)。
更新時刻取得サイトの設定(yaml形式)
設定ファイルは標準では config.yml です。 yamlに関しては、RubyでYAMLを使う等をご参考ください。
設定は以下の様になります。
サイトの設定
- http://yoosee.net/d/
の形で登録します。URI のみで設定されたサイトは、取得先サイトの title 要素、meta author 要素などから最終的に表示される「サイト名」「著者名」などの情報が自動的に参照されます。
- URI: http://yoosee.net/d/index.rdf LinkURI: http://yoosee.net/d/ Title: WorldWideWalker
サイトの更新時刻取得用URIとリンク先URIが違う場合には、上記例のように LinkURI でリンク先 URI を指定します。またタイトルが無い場合、もしくは自分でタイトルを付けたい場合には Title を指定することができます。
- http://slashdot.jp/slashdot.rdf
対象がrdfやrssの場合は、その内容からLinkURIを自動的に取得します。
より詳細なサイトの設定項目
- URI: http://example.com/ IgnorePath:
samidare では差分判定に checksum を使っていますが、IgnorePath? という XPath 風の指定により、差分更新の変更部判別時に予め無視する部分を指定することが出来ます。この指定は例えば広告により更新が正しく判別できない場合などに有効です。
IgnorePath? の設定をするために samidare --diff-content が利用できます。
% samidare --diff-content http://example.com/diary/
checksum1: 89218 [] tmp/af-example.com-diary_08-11_23:43.html
checksum1: 89792 [] tmp/af-example.com-diary_08-12_00:20.html
[["このへんが変っているよ",
"/html/body/div[3]/div[10]/a/text()"],
["例えば広告が挿入されている部分",
"/html/body/div[3]/div[10]/ul/li[1]/text()"]]
...
--- /tmp/htmldiff118468.0 2004-08-11 22:57:01.00000000 +0900
+++ /tmp/htmldiff118468.0 2004-08-11 22:57:29.00000000 +0900
@@ -1951,11 +1951,11 @@
{elem
<{http://............................
表示された変更点の XPath のうち、更新内容と直接関係のない部分の XPath を IgnorePath? として指定してやることで、更新チェックからその部分を除外することが出来るようになります。
- URI: http://example.com/diary/
IgnorePath: /html/body/div[3]/div[10]/a/text() |
/html/body/div[3]/div[10]/ul/li[1]/text()
同様の用途で使えるものとして、IgnoreID, IgnorePath? があります。それぞれ html 要素の属性である id="foo" や class="bar" を指定することが出来ます。id, class は CSS の指定などに主に使われます。
- URI: http://d.hatena.ne.jp/foobarbaz/ IgnoreClass: sidebar
例えばこの指定ははてなダイアリーの <div class="sidebar"> ... </div> で囲まれたサイドバー部分の変更を無視して更新状態を見ることができます。
外部サイトの更新情報の利用
LIRS形式の更新時刻情報を利用する事が出来ます。
-
- UpdateInfo: lirs
Periodical: true
- http://yoosee.net/a/latest.lirs.gz
HTMLファイルを解析して中から更新時刻情報を取り出すことが出来ます。
- - UpdateInfo: html Periodical: true - URI: http://www.jin.gr.jp/~nahi/link-ruby-temp.html UpdateElement: tr
実行時オプション
samidare [opts]
--help show this message
-v, --verbose verbose
-n, --no-check don't check web
-f, --force force check (avoid timing control mechanism)
-o, --output=filename specify output file
--output-lirs=filename specify output file
-T, --template=filename specify template
-t, --timing show timings
--dump-config dump flatten configuration
--dump-status dump status
--dump-template-data dump data for expand template
--dump-filenames dump filenames of specified entry
--dump-filenames2 dump two recent filenames
--remove-entry remove entry
--single-thread disable multi-threading
--diff-content show difference
Tips
更新時刻順のソート
HTree では _iter に Ruby の method を記述する事が出来ますので、ソートを行いたい場合には例えば以下のように記述する事が出来ます。
<li _iter="entries.sort_by{|e|
- e['last-modified'].to_i
}.each//entry">
ここでは各 entries コンテナ内のオブジェクト a,b を 'last-modified' で逆順 sort しており、その結果を each で entry に展開して、後の処理をしています。
カテゴリ化
config.yml 及び t.latest.html を以下の様に記述することで、各サイトをグループ化することができます。
config.yml
- - Category: Diary - http://yoosee.net/d/ - - Category: News - http://slashdot.jp/slashdot.rdf - http://ukai.org/mu/
t.latest.html
<div _iter="
[
['Diary', self['antenna'].find_all {|v| /Diary/ =~ v['Category'] }],
['News', self['antenna'].find_all {|v| /News/ =~ v['Category'] }],
].each//category,entries">
ここでは YAML の URI の並びに Category: を追加しており、それを htree のブロックの中で指定したカテゴリを検索しています。こうしたグループを複数作成することができますし、また Category 以外の条件式(例えば URI や Title 等)でグループ化する事も出来ます。
五月雨使用サイト
五月雨を御利用されているサイトがありましたら以下にご記入ください
- 2004-04-27 (火) 11:26:46 みうら? : ヨポポ
更新履歴
- 2006-10-12 spamのためページ・コメント欄を凍結
- 2004-08-12 Template, IgnorePath? 等の記述を修正して記載
- 2004-08-11 ほぼ全体の記述を htree 版五月雨にあわせて修正
- 2003-11-11 全体の記述を Tempura 使用版五月雨にあわせて修正
- 2003-10-30 カテゴリ化サンプルを Tempura 対応にしてみた
- 2003-10-28 暮らしの業(2003-10-24) より Xtemplate から Tempura へ変更
- 2003-10-23 サイトの配置変更
- 2003-10-22 \ay diary(2003-10-11) を参考にして IgnorePath? 及び htmldiff, htmlign の記述を追加
- 2003-10-22 Debian でのインストール記述を追加
- 2003-10-22 五月雨利用サイト一覧の項目を作成
- 2003-10-11 ページ作成

キーワード:
参照:[(WebTech)五月雨] [Web/Samidare]