LoginSignup
7
7

More than 5 years have passed since last update.

Hubot | 自作Script | qiita_new.coffee - Qiitaの新規記事からランダムで取得した1件を表示する

Posted at

Hubot | 自作Script | qiita_new.coffee - Qiitaの新規記事からランダムで取得した1件を表示する

概要

qiita_new.coffee - Qiitaの新規記事からランダムで取得した1件を表示する

用途

  • Qiitaの新規記事を読んでみたいお年ごろの時

仕様

filename

qiita_new.coffee

respond or hear

respond

起動メッセージ

  • 正規表現
/qiita new/i

Qiita DevAPI

QiitaのAPIについては下記参照
http://qiita.com/docs/api#12

今回取得するのは新規投稿です。

ソースコード

# Description
#   Output Qiita new article(random).
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   hubot qiita new ... - Output qiita new article(random)
#
# Author:
#   tbpgr
module.exports = (robot) ->

  robot.respond /qiita new/i, (msg) ->
    robot.http("https://qiita.com/api/v1/items")
      .get() (err, res, body) ->
        articles = JSON.parse(body)
        article = msg.random(articles)
        msg.send "title:#{article['title']}"
        msg.send "url => "
        msg.send article['url']
        msg.send "author:#{article['user']['url_name']}"

試行結果

$ ./bin/hubot

Hubot> title:Project Eulerをhaskellで練習していく日記: Problem 2
Hubot> author:hiroshi75
Hubot> url =>
Hubot> http://qiita.com/hiroshi75/items/33fd2e780fc702b7266b
Hubot> hubot qiita new
Hubot> hogehoge
Hubot> title:Boot2Dockerを試す (Windows)
Hubot> author:pomutemu
Hubot> url =>
Hubot> http://qiita.com/pomutemu/items/72d0fb9cf8eed465da5d
Hubot> hubot qiita new
Hubot> hogehoge
Hubot> title:NutchでクロールしたWebページをSolrで検索する
Hubot> author:pika-shi@github
Hubot> url =>
Hubot> http://qiita.com/pika-shi@github/items/b7e8fb356aca244ba099

補足

今のところ、 npm で公開したりする予定はないので適当にGitHubに突っ込んでおきます。
https://github.com/tbpgr/hubot_scripts

7
7
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
7
7