Last active
October 8, 2015 10:08
-
-
Save rike422/0041ab1fdde2298f5094 to your computer and use it in GitHub Desktop.
電車遅延ゲット
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Search and show your train time in Japan | |
# | |
# Dependencies: | |
# "cheerio-httpcli", "" | |
# | |
# Configuration: | |
# None | |
# | |
# Commands: | |
# hubot delay <name> | |
# hubot 電車遅延 <name> | |
# | |
# Author: | |
# 3100 | |
client = require "cheerio-httpcli" | |
module.exports = (robot) -> | |
fondLine = () -> | |
""" | |
知らない路線です。 | |
http://transit.loco.yahoo.co.jp/traininfo/area/4/ | |
から探してください。 | |
""" | |
manyLine = (lines) -> | |
""" | |
絞り込めませんね。下のどれかでしょうか? | |
#{lines.map((line) -> " * #{line.text}").join('\n')} | |
""" | |
getInfo = (msg) -> | |
client.fetch("http://transit.loco.yahoo.co.jp/traininfo/area/4/", {} ,(err, $, res) -> | |
lines = $("#mdAreaMajorLine .elmTblLstLine > table tr a") | |
.toArray() | |
.map((a) -> { text: $(a).text(), href: a.attribs.href }) | |
.filter((a) -> a.text.search(msg.match[2]) != -1) | |
return msg.send fondLine() if lines.length == 0 | |
return msg.send manyLine(lines) if lines.length > 1 | |
client.fetch(lines[0].href, {}, (err, $, res) -> | |
msg.send "#{msg.match[2]}: #{$('#mdServiceStatus').text()}" | |
) | |
) | |
robot.respond /(delay|電車遅延) ([^ ]+)/i, (msg) -> | |
getInfo(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment