LoginSignup
5
5

More than 5 years have passed since last update.

Hubotで定期的にはてブITカテゴリのホットエントリを呟かせてみる

Last updated at Posted at 2015-04-26

会社でLet's Chat&Hubotを試しに運用し始めたので、開発チームの話題提供用に定期的にはてブITカテゴリのホットエントリを呟かせるスクリプト書いてみた。

hubot_hatebu_it.coffee
cronJob = require('cron').CronJob
to_json = require('xmljson').to_json
request = require 'request'
module.exports = (robot) ->
  new cronJob '00 30 09,12,15,18 * * 1-5', () =>
    url = "http://b.hatena.ne.jp/hotentry/it.rss"
    options =
      url: url
      timeout: 2000
      headers: {'user-agent': 'node title fetcher'}
    request options, (error, response, body) ->
      to_json body, (err, data) =>
        article = "はてブITカテゴリ ホットエントリ¥n"
        for id, item of data["rdf:RDF"].item
          title = item.title
          link  = item.link
          article += "#{title} #{link}¥n"
        robot.send {room:"ROOM_ID"}, article
  , null, true, "Asia/Tokyo"


↓の記事を参考にRSSを取得して、パースしてタイトルとURL要素から文章を生成して呟かせる。

はてブAPIでwebサービスを作りたい全ての人に向けて書きました


  1. package.jsonにcron・xmljson・requestを追記
  2. 今回のスクリプトを適当にscriptディレクトリに放り込む

で準備完了。

指定した時間になったらつぶやいてくれる。

30件は流石にウザったいので個数減らそうかと検討中。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5