LoginSignup
7
7

More than 5 years have passed since last update.

Hubot | 自作Script | codeiq_new.coffee - CodeIQの新着問題をRSSから取得する

Posted at

Hubot | 自作Script | codeiq_new.coffee - CodeIQの新着問題をRSSから取得する

概要

codeiq_new.coffee - CodeIQの新着問題をRSSから取得する

xmlのparseには xml2js を利用します。

用途

  • 目的より手段的なものなので特に目的はない

仕様

filename

codeiq_new.coffee

respond or hear

respond

起動メッセージ

  • 正規表現
/codeiq new_all$/
/codeiq new_(\d+)$/

new_all は全件取得
new_N は全件取得時のnoを元に、1件だけ詳細を確認したい場合に使用します

CodeIQ RSS

CodeIQの新着問題RSS の URL は以下
https://codeiq.jp/rss.xml

ソースコード

# Description
#   Output CodeIQ new problem.
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   hubot codeiq new_N ... - Output a codeiq new problem
#   hubot codeiq new_all ... - Output codeiq all new problems
#
# Author:
#   tbpgr
xml2js = require('xml2js')
parseXML = xml2js.parseString
module.exports = (robot) ->

  robot.respond /codeiq new_(\d+)$/i, (msg) ->
    qno = parseInt(msg.match[1])
    robot.http("https://codeiq.jp/rss.xml")
      .get() (err, res, body) ->
        parseXML body, (err, xml) ->
          qs = xml.rss.channel[0].item
          qno = qs.length if qno > qs.length
          qno = 1 if qno = 0
          q = qs[qno - 1]
          msg.send "no = #{qno}"
          msg.send "title = #{q.title}"
          msg.send "url = #{q.link}"
          msg.send "description = #{q.description}"
          msg.send "author = #{q.category}"

  robot.respond /codeiq new_all$/i, (msg) ->
    robot.http("https://codeiq.jp/rss.xml")
      .get() (err, res, body) ->
        parseXML body, (err, xml) ->
          xml.rss.channel[0].item.forEach (q, i) ->
            msg.send "no = #{i + 1}| #{q.title}"

試行結果

$ ./bin/hubot

Hubot>
Hubot> hubot codeiq new_all
Hubot> no = 1| 挑戦者求む!【アルゴリズム】今週のお題:面倒なキャッチボール by 増井技術士事務所 今週のアルゴリズムの@masuipeo
Hubot> no = 2| 挑戦者求む!【ハッキング】Adminパスワードを破れ! by 株式会社サイバーディフェンス研究所 福森 大喜
Hubot> no = 3| 挑戦者求む!【LTSV】LTSVをparseしよう by @tbpgr tbpgr(バッジ付与問題)
Hubot> no = 4| 挑戦者求む!【Java】テンタメ!「三つ子カフェデビュー」 by 株式会社パワーハウス ふぉっくす小隊
Hubot> no = 5| 挑戦者求む!【Java】テンタメ!「三つ子のお菓子の行方」 by 株式会社パワーハウス ふぉっくす小隊
Hubot> no = 6| 挑戦者求む!【LTSV】TSVファイルをLTSVに変換しよう by @tbpgr tbpgr(バッジ付与問題)
Hubot> no = 7| 挑戦者求む!【ウチに来ない?】巨大な整数の演算を行ってみよう! by フリュー株式会社 フリュー(株) 出題担当
Hubot> no = 8| 挑戦者求む!【Linux】Linux応用-ネットワーク構成 by 有限会社ネットワーク・メンター 笠野 英松
Hubot> no = 9| 挑戦者求む!【アルゴリズム】今週のお題:いまだに現金払い? by 増井技術士事務所 今週のアルゴリズムの@masuipeo
Hubot> no = 10| 挑戦者求む!【ウチに来ない?】Java:アイテム類似度のレコメンド by CodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 11| 挑戦者求む!【Ruby】yieldのお勉強 Lv.2 by @antimon2 antimon2
Hubot> no = 12| 挑戦者求む!【Python】yieldのお勉強 Lv.2 by @antimon2 antimon2
Hubot> no = 13| 挑戦者求む!【Objective-C】来年のクリスマスは何曜日? by @makotoo2 大津 真
Hubot> no = 14| 挑戦者求む!【ウチに来ない?】C#:フィギュアを最高額で売ろう byCodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 15| 挑戦者求む!【ウチに来ない?】Py:グーテンベルグ印刷の活字 by CodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 16| 挑戦者求む!【ウチに来ない?】C++:島の多いエーゲ海 by CodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 17| 挑戦者求む!【ウチに来ない?】PHP:海平の怒りを最小限にせよ by CodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 18| 挑戦者求む!【ウチに来ない?】JS:素数と醜いアヒルのコード by CodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 19| 挑戦者求む!【ウチに来ない?】言語不問:素数の数を数えてください by CodeIQ運営事務局 アプリケーションエンジニアを募集する企業
Hubot> no = 20| 挑戦者求む!【アルゴリズム】モーニングクエスト:フィボナッチ数列 by @cielavenir ciel "[挑戦受付は終了しました]"
Hubot>
Hubot> hubot codeiq new_3
Hubot> no = 3
Hubot> title = 挑戦者求む!【LTSV】LTSVをparseしよう by @tbpgr tbpgr(バッジ付与問題)
Hubot> url = https://codeiq.jp/ace/tbpgr_badge/q1024?utm_medium=rss&utm_source=rss&utm_campaign=owned
Hubot> description = LTSV形式のファイルを好きな言語でparseしよう(挑戦受付締切予定 2014年9月1日 AM10:00)
Hubot> author = @tbpgr

補足

今のところ、 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