LoginSignup
6
5

More than 5 years have passed since last update.

Hubot | 自作Script | Hubot で 「フォト蔵」API の結果を取得する

Posted at

Hubot | 自作Script | Hubot で 「フォト蔵」API の結果を取得する

概要

Hubot で 「フォト蔵」API の結果を取得します

機能

  • Queryで検索ワードを指定
  • 検索ワードに一致するデータを10件取得し、ランダムで一件を表示する

正規表現

/photozou( (.*))/i

ソースコード

photozou.coffee
# Description
#   Output photozou
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   hubot photozou <query>... - Output photozou
module.exports = (robot) ->
  robot.respond /photozou( (.*))/i, (msg) ->
    query = msg.match[2]
    robot.http("https://api.photozou.jp/rest/search_public.json?keyword=#{query}&limit=10")
      .get() (err, res, body) ->
        photos = JSON.parse(body)['info']['photo']
        photo = msg.random(photos)
        msg.send "title:#{photo}"
        msg.send "title:#{photo['photo_title']}"
        msg.send "image_url => "
        msg.send photo['image_url']

出力

shell adapter で確認

Hubot> hubot photozou cat
Hubot> title:kakegawajyo_cat0_DSC04172
Hubot> image_url =>
Hubot> http://art9.photozou.jp/pub/929/2335929/photo/209744964.jpg
Hubot> hubot photozou cat
Hubot> title:分かりゃいいんだよ分かりゃ...
Hubot> image_url =>
Hubot> http://art9.photozou.jp/pub/651/2827651/photo/209756518.jpg

参照

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