Last active
August 29, 2015 14:16
-
-
Save nanonanomachine/f8d68b5163a9ddbf9eca to your computer and use it in GitHub Desktop.
雨の日警告ちゃん
This file contains 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
cron = require('cron').CronJob | |
request = require 'request' | |
cities = | |
"横浜": "140010" | |
"金沢": "170010" | |
apiUrl = 'http://weather.livedoor.com/forecast/webservice/json/v1?city=' | |
sendBadForecast = (robot, label, id) -> | |
request apiUrl + id, (err, response, body) -> | |
if err | |
robot.logger.debug "Weather Alert Request error: #{err}" | |
if response.statusCode is 200 # 取得成功 | |
try | |
json = JSON.parse body | |
catch e | |
robot.logger.debug "JSON parse error: #{e}" | |
# 明日の予報データを取得 | |
forecast = json.forecasts[json.forecasts.length-2] | |
# 雨とか雪の日だったら | |
if forecast.telop.indexOf('雨') isnt -1 or forecast.telop.indexOf('雪') isnt -1 | |
text = "明日の#{label}の天気悪そうです...\n" + | |
"予報:#{forecast.telop}\n" + | |
"最高気温:#{forecast.temperature.max.celsius}℃\n" + | |
"最低気温:#{forecast.temperature.min.celsius}℃\n" + | |
"詳しい情報は下記を参照\n\n" + | |
"#{json.link}" | |
robot.send {room: "experiment"}, text | |
module.exports = (robot) -> | |
job = new cron '30 23 * * *', () => | |
for key, value of cities | |
sendBadForecast robot, key, value | |
job.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment