View All Posts. MiCHiLU.com powered by Django ;-)

[Python]: Python版Plagger pyhabuを使ってみる

Python版の Plagger ともいえる pyhabu を使ってみます。 レシピに沿って小さなplugin scriptをUNIX pipeのように連結させ、多様な仕事をさせるものです。 例えば、いろんなものをダウンロードしたりとか。 Twisted , feedparser , PyYAML が必要です。

Twisted

http://twistedmatrix.com/trac/wiki/Downloads

詳細を忘れたので割愛。 詳しくは他の文献を参照してください。

feedparser

$ svn co http://feedparser.googlecode.com/svn/trunk feedparser

PyYAML

$ svn co http://svn.pyyaml.org/pyyaml/trunk pyyaml

feedparser, PyYAML は PYTHONPATH を通せばOKです。

pyhabu

$ svn co http://svn.sourceforge.jp/svnroot/pyhabu/trunk pyhabu
$ cd pyhabu

$ python runhabu.py -h
Usage : runhabu.py [options] [config_file_path]
Valid Options:
  -h, --help: Show this message.
  -v, --version: Show Version
  -t, --target=TARGET_PIPELINE: Run specific pipeline.
  -a, --plugin-path=PLUGIN_PATH: Append plugin paht.
  --download-module=PLUGIN_NAME: download specified plugin.
  --download-url=DOWNLOAD_URL: download from specified urln.
  -e, --enable-netinstall: enable to install module from net.
  -d, --disable-server: disable server functions
  -l, --log-level=LOG_LEVEL: set log level.
  --log-file=LOG_FILE: set log files. if stdout, ouput to stdout.
  --proxy-host=PROXY_HOST_NAME: Proxy Host Name.
  --proxy-port=PROXY_HOST_NUMBER: Proxy Host Port Number.
  --pid-file=PID_FILE_PATH
$ python runhabu.py -V
habu 0.3.0

オプションなしで実行すると、付属のレシピ(habu.cfg)が実行されます。 レシピは YAML 形式で書きます。

habu.cfg

global:
  timezone: Asia/Tokyo
  log: stdout

pipeline:
  rss_fetcher:
    - module: subscription.config
      config:
        feed:
          - http://www.liris.org/blog/RSS
          - http://dev.ariel-networks.com/Members/blog_update/RSS
    - module: filter.join
    - module: filter.sort
      config:
        reverse: True
    - module: publisher.rssfeeder
      config:
        file: "out.rss"

このレシピでは、

というように動作します。

$ python runhabu.py
2007/10/11 23:59 +0900 [-] Log opened.
2007/10/11 23:59 +0900 [-] Started habu with Task Mode
2007/10/11 23:59 +0900 [-] habu.webutils.getPage : http://dev.ariel-networks.com/Members/blog_update/RSS
2007/10/11 23:59 +0900 [-] Starting factory <HTTPClientFactory: http://dev.ariel-networks.com/Members/blog_update/RSS>
2007/10/11 23:59 +0900 [-] habu.webutils.getPage : http://www.liris.org/blog/RSS
2007/10/11 23:59 +0900 [-] Starting factory <HTTPClientFactory: http://www.liris.org/blog/RSS>
2007/10/11 23:59 +0900 [HTTPPageGetter,client] Stopping factory <HTTPClientFactory: http://dev.ariel-networks.com/Members/blog_update/RSS>
2007/10/11 23:59 +0900 [HTTPPageGetter,client] Thread Joined
2007/10/11 23:59 +0900 [-] Stopping reactor
2007/10/11 23:59 +0900 [HTTPPageGetter,client] Stopping factory <HTTPClientFactory: http://www.liris.org/blog/RSS>
2007/10/11 23:59 +0900 [-] Main loop terminated.
$ ls out.rss
out.rss

どのpathからでも実行できるように runhabu.py にpathを通しておきます。

Tue, 16 Oct 2007 02:59:42 +0900 source edit
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.1 Japan License.
View All Posts. MiCHiLU.com powered by Django ;-)