Feedを定期的に取得してIRCに投げる

という事をやってみようと思った。ウチはTracを使ってるのでTimelineからFeedをとって来てTracの更新の内容を、社内のIRCサーバに垂れ流してみたかったのですよ。
以下やり方。

1.Plaggerのインストール

自分のローカルマシンにcolinuxを入れて、そこにPlaggerをインストール
Plaggerのインストールはそのウチ書くかも。けどググッた方が早い。

2.IRCボットを立ち上げる。

Plaggerをインストールすると「/usr/bin」以下に「plagger-ircbot」見たいのがインストールされてる。
下記のような設定ファイル(ここでは、irc.ymlとかしてみる)を用意して、IRCボットを起動。

plugins:
  - module: Notify::IRC
    config:
      daemon_port: 9999            #IRCボット動くポート番号(colinux)
      nickname: nickname           #IRC上でのアカウント名
      server_host: xxx.xxx.xxx.xxx #IRCサーバのIP
      server_port: xxxx            #IRCサーバのポート番号
      server_channels:
        - #hogehoge           #IRCのチャットルーム名(フィードを流す場所)
      charset: ISO-2022-JP         #IRCサーバの文字コード
      announce: notice             # ? 良く分からん 

そしたら下記のような感じで起動

plagger-ircbot -c irc.yml

こんなメッセージが出たらおk

[msg] loading configuration irc.yml
[msg] creating daemon component
[msg] creating irc component
[msg] creating kernel session
[msg] starting irc session
[msg] starting the kernel
[msg] attempting to connect to server
Received line :hogehoge.net 005 hogehoge WHOX WALLCHOPS WALLVOICES USERIP CPRIVMSG CNOTICE SILENCE=15 MODES=6 MAXCHANNELS=15 MAXBANS=45 NICKLEN=9 TOPICLEN=160 AWAYLEN=160 KICKLEN=160 :are supported by this server that is not IRC protocol
[msg] joining channel #phogehoge
[msg] [motd] Type /MOTD to read the AUP before continuing using this service.
[msg] [motd] The message of the day was last changed: 2003-3-23 23:14

3.Plaggerでフィードを取得してボットに渡す。

フィードを取得してIRCボットに投げる設定ファイル(ここではfeed.ymlとする)を書く。

global:
  timezone: Asia/Tokyo
  log:
    level: debug
  cache:
    base: /home/tell-k/plagger-cache

plugins:
  - module: Subscription::Config
    config:
      feed: #フィードのURL
        - http://hogehoge.net/trac/hoge/timeline?milestone=on&ticket=on&changeset=on&wiki=on

  - module: Aggregator::Simple
  - module: Filter::Rule
    rule:
      - module: Deduped
    path: /home/tell-k/plagger-irc.log

  - module: Notify::IRC
    config:
     daemon_port: 9999     #IRCボットのポート番号
     charset: ISO-2022-JP  #IRCサーバの文字コード(これがないと何故かlimechatおとかで文字化ける?)

んで下記コマンドを叩く

plagger -c feed.yml

こんな感じのメッセージが出ればおk。

Plagger [info] plugin Plagger::Plugin::Subscription::Config loaded.
Plagger [info] plugin Plagger::Plugin::Aggregator::Simple loaded.
Plagger [info] plugin Plagger::Plugin::Filter::Rule loaded.
Plagger [info] plugin Plagger::Plugin::Notify::IRC loaded.
Plagger [info] plugin Plagger::Plugin::Bundle::Defaults loaded.
Plagger [info] plugin Plagger::Plugin::Summary::Auto loaded.
Plagger [info] plugin Plagger::Plugin::Summary::Simple loaded.
Plagger [info] plugin Plagger::Plugin::Namespace::HatenaFotolife loaded.
Plagger [info] plugin Plagger::Plugin::Namespace::MediaRSS loaded.
Plagger [info] plugin Plagger::Plugin::Namespace::ApplePhotocast loaded.
Plagger::Plugin::Aggregator::Simple [info] Fetch http://hogehoge.net/trac/hogehoge/timeline?milestone=on&ticket=on&changeset=on&wiki=on&max=10&daysback=90&format=rss
Plagger::Cache [debug] Cache MISS: Aggregator-Simple|http://hogehoge.net/trac/hoge/timeline?milestone=on&ticket=on&changeset=on&wiki=on&max=10&daysback=90&format=rss
Plagger::Plugin::Aggregator::Simple [debug] 200: http://hogehoge.net/trac/hoge/timeline?milestone=on&ticket=on&changeset=on&wiki=on&max=10&daysback=90&format=rss
  • IRCのチャットルームに行けば、フィードが流れてくる様が確認できる。。。ハズ。

4.定期的にcronでフィードをIRCに流す

さっきのコマンドを定期的に手で叩くのは当然だるいので、cronに叩かせる。

crontab -e

でcrontabを編集。こんな感じ。

#30分間隔で、叩く
 */30 *   *   *   *   /usr/bin/plagger -c /home/tell-k/feed.yml

余談だけど、上のコマンドを叩くと。一度取得したフィードの内容はローカルにキャッシュされて、次回叩いた時には差分しかIRCに流さないようになってる。おりこうさん(今回の例だと/home/tell-k/plagger-cache以下に出来てる)

さてこれで全部おわり。。。。のハズだったが、何故かcronが動かない。。。。何故?それは次回を待て。