LoginSignup
3
1

More than 5 years have passed since last update.

Node.jsでconnpassの自分が管理しているイベント( #iotlt )の情報を取得

Last updated at Posted at 2017-12-01

こんにちは、IoTLTを主催しているn0bisukeです。

IoTLTでのconnpass自動化話(Headless Chromeでconnpassの編集作業を半自動化している話)の中からconnpassのAPI利用部分を切り出して記事にします。

IT勉強会/コミュニティ運営 Advent Calendarということで、イベント管理の参考になれば幸いです。

やりたいこと

connpassのイベントページから、直近のIoTLTのイベントを知りたい。

実際にやりたいことの詳細はこちらの記事を参照してください。ざっくりいうとconnpassの自動更新です。

要件

IoTLTでは地方開催やスピンオフなど各種イベントが立ち上がっています。その中で、僕が登壇者の管理を行う本体のイベントの直近開催のイベントの情報を取得したいです。

connpassのAPIから取得

connpassはAPIがあって情報の取得は可能です。

https://connpass.com/about/api/

例えばowner_nicknameを指定すると自分が主催しているイベントを取得できます。

https://connpass.com/api/v1/event/?owner_nickname=n0bisuke

ただこれだと過去の終了したイベントも引っかかってくるので、ymで開催月を指定します。

直近の開催 = 今月、来月、再来月ということにして再来月までを指定します。

この辺はmoment.jsを利用すると簡単です。

最後は正規表現で

本体イベントはIoT縛りの勉強会! IoTLT vol.xxといったタイトル付けルールになっていて、その他の地方開催はxx版IoT縛りの勉強会! IoTLTxxというタイトルになっていて、若干タイトルが違うのでそこで判断します。

(結構無理やりですが.....)

実装

npm init -y
npm i --save axios moment
getmyevent.js
'use strict';

const axios = require('axios');
const moment = require('moment');
const DATE_RANGE = [
    moment().format('YYYYMM'), //今月
    moment().add(1,'months').format('YYYYMM'), //来月
    moment().add(2,'months').format('YYYYMM') //再来月
];
//console.log(DATE_RANGE.join(',')); -> 201712,201801,201802など
const API = `https://connpass.com/api/v1/event/?owner_nickname=n0bisuke&ym=201712,201801,201802${DATE_RANGE.join(',')}&count=20&order=2&keyword=IoTLT`;

const main = async () => {
    const res = await axios.get(API);
    const events = res.data.events;
    let result = {};

    for(let i = 0, len = events.length; i < len; i++){
        if(!events[i].title.match(/IoT縛りの勉強会! IoTLT vol.\d{2}/)) continue; //本体の回以外はスルー
        if(moment().isSameOrAfter(events[i].started_at)) continue; //実施済みイベントはスルー
        result = events[i];
        break;
    }

    console.log(result);
}
main();

実行結果

$ node getmyevent.js

{ event_url: 'https://iotlt.connpass.com/event/73416/',
  event_type: 'participation',
  owner_nickname: 'n0bisuke',
  series:
   { url: 'https://iotlt.connpass.com/',
     id: 1121,
     title: 'IoT縛りの勉強会\u0010! IoTLT' },
  updated_at: '2017-12-01T18:15:25+09:00',
  lat: '35.658889000000',
  started_at: '2017-12-26T19:00:00+09:00',
  hash_tag: 'iotlt',
  title: '【増席】IoT縛りの勉強会\u0010! IoTLT vol.34 @ teratail (レバレジーズ)',
  event_id: 73416,
  lon: '139.703333000000',
  waiting: 0,
  limit: 234,
  owner_id: 18821,
  owner_display_name: 'n0bisuke',
  description: '<h2>業界初?! IoT縛りの勉強会/LT会です! 大好評を受けての第34回開催!</h2>\n<p>IoTというワードがバズワードになりつつあります。<br>\nとはいえ、IoT領域には関連する幅広い知識や技術があります。</p>\n<p>また、アイディアやインスピレーションも重要です。</p>\n<p>この会は個々が持っている知識や開発していることの情報共有や発信の場になります。 <br></p>\n<p>開催に至った経緯や今後の展開はこちら <br>\n<a href="https://codeiq.jp/magazine/2016/03/38409/" rel="nofollow">https://codeiq.jp/magazine/2016/03/38409/</a></p>\n<h2>開催前後の交流ためのFBグループもあります!</h2>\n<p><a href="https://www.facebook.com/groups/IoTLT" rel="nofollow">https://www.facebook.com/groups/IoTLT</a> <br>\n情報はこちらで流れてるので是非ご参加下さい!</p>\n<h3>登壇希望者はFBコメントください!</h3>\n<p><a href="https://www.facebook.com/groups/IoTLT/permalink/852288551608927/" rel="nofollow">こちら</a>にコメントください!</p>\n<ul>\n<li>11/29 公開</li>\n</ul>\n<h2>会場はレバレジーズ株式会社</h2>\n<ul>\n<li>エンジニア向けQAサービス <a href="https://teratail.com/" rel="nofollow">teratail</a></li>\n</ul>\n<p><strong>人数が多い場合は立ち見になる可能性もございます。あらかじめご了承ください。</strong></p>\n<h3>アクセス</h3>\n<p>渋谷駅直結 渋谷ヒカリエ 17F</p>\n<h3>入館方法</h3>\n<h2>タイムテーブル</h2>\n<p>LTは一人5分です。</p>\n<table>\n<thead>\n<tr>\n<th align="left">時間</th>\n<th align="left">内容</th>\n<th align="left">発表者</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align="left">19:00</td>\n<td align="left">開場</td>\n<td align="left"></td>\n</tr>\n<tr>\n<td align="left">19:30</td>\n<td align="left">オープニング</td>\n<td align="left"></td>\n</tr>\n<tr>\n<td align="left">19:40</td>\n<td align="left">LT開始</td>\n<td align="left"></td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: テラテイル様</td>\n<td align="left"><strong>スポンサーLT</strong></td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: 未定</td>\n<td align="left">未定</td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: 未定</td>\n<td align="left">未定</td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: 未定</td>\n<td align="left">未定</td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: 未定</td>\n<td align="left">未定</td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: 未定</td>\n<td align="left">未定</td>\n</tr>\n<tr>\n<td align="left"></td>\n<td align="left">LT: のびすけ at dotstudio</td>\n<td align="left">LINE BOTと何かやる</td>\n</tr>\n<tr>\n<td align="left">21:00</td>\n<td align="left">懇親会</td>\n<td align="left"></td>\n</tr>\n<tr>\n<td align="left">21:45</td>\n<td align="left">中締め</td>\n<td align="left"></td>\n</tr>\n<tr>\n<td align="left">22:00</td>\n<td align="left">撤収</td>\n<td align="left"></td>\n</tr>\n</tbody>\n</table>\n<p>IoTに興味のある、ハードウェア/Webエンジニアの方を中心にどなたでもご参加できます!</p>\n<h2>参加費</h2>\n<ul>\n<li>本編 無料</li>\n<li>懇親会 1000円(仮)</li>\n</ul>\n<h2>主催</h2>\n<h3>リレーションズ株式会社 <a href="https://www.facebook.com/tsuchiya.taka" rel="nofollow">土屋敬</a></h3>\n<p>自転車シェアサービスCOGOO、SELECKなどを運営する会社です。</p>\n<p><a href="http://www.relationsgroup.co.jp/" rel="nofollow">http://www.relationsgroup.co.jp/</a></p>\n<ul>\n<li>COGOO <a href="http://cogoo.jp/" rel="nofollow">http://cogoo.jp/</a></li>\n<li>SELECK <a href="https://seleck.cc/top" rel="nofollow">https://seleck.cc/top</a></li>\n</ul>\n<h3>dotstudio株式会社 <a href="https://dotstud.io/members/n0bisuke/" rel="nofollow">菅原のびすけ</a></h3>\n<p>2016年7月からdotstudio株式会社を立ち上げました</p>\n<ul>\n<li><a href="https://dotstud.io/blog/we-started-dotstudio-inc/" rel="nofollow">dotstudio株式会社 設立のご報告</a></li>\n</ul>\n<h2>諸注意</h2>\n<ul>\n<li>イベント内容は一部変更になる可能性がございます。</li>\n<li>イベント当日の様子は後日何らかの媒体にて公開させていただくことがございます。</li>\n<li>お申込後運営都合によりご参加をキャンセルさせて頂く場合がございます。予めご了承頂けますようお願いいたします。</li>\n</ul>',
  address: '東京都渋谷区渋谷2-21-1  渋谷ヒカリエ17F ',
  catch: '【年内ラスト!忘年会!】菅原のびすけ(dotstudio)/土屋敬(Relations)',
  accepted: 176,
  ended_at: '2017-12-26T22:00:00+09:00',
  place: 'レバレジーズ株式会社' }

こんな感じで、最新の僕の管理イベントIoTLT vol34だけが取得できました!

所感

開催済みのイベントは検索に載せないなどのオプションや、開催場所検索
(keywordで住所の情報も引っ張れるっぽいけど本文に東京って書いてあるのか本当に東京開催なのか分からない)などもあるともっと簡単に抜き出したい情報を抜き出せそうだなぁという印象です。

とはいえAPIがあるのは嬉しいですね。

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