1
0

More than 1 year has passed since last update.

LIFE WILL Emodiversity APIのemotion_mapを使ってみたメモ

Last updated at Posted at 2021-10-28

これはなに

LIFULLさんから出ている年月から地域の感情を分析結果を取得するAPIのメモです。

emotion_analyzeについてのメモはこちら

どんなものかのデモはこちらで体験できます。
https://lab.lifull.com/lifewill/emodiversity/map/

tokenの申請は以下のページを見てください。
https://lab.lifull.com/lifewill/emodiversity/api-docs/index.html

今回利用するemotion_mapのドキュメントはこちら
https://lab.lifull.com/lifewill/emodiversity/api-docs/reference/emotion_map.html

APIの呼び方

Node.js

const request = require("request");
request.post({
    url: "https://lab.lifull.com/lifewill/api/v1/emotion_map",
    headers: {
        "token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    },
    form: { year: 2021, month: 5 },
    json: true
}, function (error, response, body) {
    const emoMaps = body.emotions;
    if (!error) {
        const emoList = ["ドキドキ", "ワクワク", "キュンキュン", "ニコニコ", "ホノボノ", "ユルユル", "ウトウト", "シクシク", "モヤモヤ", "ツンツン", "ピリピリ", "ソワソワ"];
        for (let emo of emoMaps) {
            emo.emotion_text = emoList[emo.emotion - 1];
        }
    }
    console.log(emoMaps);
});

※既存のデータではemotionの番号(1-12)しかこないので、テキストを追加するプログラムが追加しています。

取得できるデータ

実際のサンプル

{
  emotions: [
    { emotion: 3, jis_code: 11002, name: '札幌市' },
    { emotion: 3, jis_code: 12025, name: '函館市' },
    { emotion: 3, jis_code: 12033, name: '小樽市' },
    { emotion: 8, jis_code: 12041, name: '旭川市' },
    { emotion: 11, jis_code: 12050, name: '室蘭市' },
    { emotion: 11, jis_code: 12068, name: '釧路市' },
    { emotion: 3, jis_code: 12076, name: '帯広市' },
    { emotion: 9, jis_code: 12084, name: '北見市' },
    { emotion: 6, jis_code: 12092, name: '夕張市' },
    { emotion: 2, jis_code: 12106, name: '岩見沢市' },
    { emotion: 2, jis_code: 12114, name: '網走市' },
    { emotion: 9, jis_code: 12122, name: '留萌市' },
    { emotion: 11, jis_code: 12131, name: '苫小牧市' },
    { emotion: 9, jis_code: 12149, name: '稚内市' },
    { emotion: 7, jis_code: 12157, name: '美唄市' },
    { emotion: 1, jis_code: 12165, name: '芦別市' },
    { emotion: 1, jis_code: 12173, name: '江別市' },
    { emotion: 11, jis_code: 12181, name: '赤平市' },
    { emotion: 2, jis_code: 12190, name: '紋別市' },
    { emotion: 8, jis_code: 12203, name: '士別市' },
    { emotion: 6, jis_code: 12211, name: '名寄市' },
    { emotion: 11, jis_code: 12220, name: '三笠市' },
    { emotion: 6, jis_code: 12238, name: '根室市' },
...(略)...
  ],
  result: 'success',
  update: '2021-05-31 03:41:18.9311'
}

取得すると全市町村分が来ますのでデータ量が非常に多いです。
※2021年10月現在で1709
jis_codeに関してはこちらを参考にしてください。
https://www.soumu.go.jp/denshijiti/code.html

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