Help us understand the problem. What is going on with this article?

hubot + ぐるなびAPIで飲食店検索

More than 5 years have passed since last update.

Installation

$ npm install hubot-harahe --save

インストールしたら harahe.coffee を編集して API Key と検索アドレスを入力してください。

https://www.npmjs.com/package/hubot-harahe

scripts/harahe.coffee

# Description:
#   Get restaurant data from Gurunavi API
#
# Commands:
#   hubot harahe - Reply with restaurant info

Client = require("node-rest-client").Client
client = new Client()
parseString = require('xml2js').parseString

apiHost     = 'http://api.gnavi.co.jp/RestSearchAPI/20150630/?'
keyId       = 'YOUR API KEY ID'
address     = '福岡県福岡市博多'
hitPerPage  = 1

module.exports = (robot) ->
  robot.respond /HARAHE ?(.*)$/i, (msg) ->
    attr = msg.match[1].trim()
    address = attr if attr != ""
    req = "#{apiHost}keyid=#{keyId}&hit_per_page=#{hitPerPage}&offset_page=1&address=#{encodeURIComponent(address)}"

    client.get req, (data, response) ->
      parseString data, (err, result) ->
        totalCount = result['response']['total_hit_count']
        offsetPage = Math.floor Math.random() * totalCount
        req = "#{apiHost}keyid=#{keyId}&hit_per_page=#{hitPerPage}&offset_page=#{offsetPage}&address=#{encodeURIComponent(address)}"

        client.get req, (data, response) ->
          parseString data, (err, result) ->
            items = result['response']['rest'][0]
            msg.send "Recommend: #{items['name']}"
            msg.send "Category: #{items['category']}"
            msg.send "Address: #{items['address']}"
            msg.send "URL: #{items['url']}"
            msg.send "Image: #{items['image_url'][0]['shop_image1']}"

https://gist.githubusercontent.com/taketin/146d1412d11f5596770b/raw/harahe.coffee

total_hit_count 取得するためにAPI2回叩いてるのがエコじゃない..

Usage

get ぐるなびAPI key id

http://api.gnavi.co.jp/api/use.html

run hubot

# default address
hubot harahe

# with address
hubot harahe 福岡市天神

enjoy!

taketin
最近は iOSアプリケーション をメインに開発しています
https://github.com/taketin
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした