Skip to content

Instantly share code, notes, and snippets.

@tamoot
Forked from jeremykarn/awsstatus.coffee
Created June 30, 2014 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamoot/07b70d7e049cb6c9c2e1 to your computer and use it in GitHub Desktop.
Save tamoot/07b70d7e049cb6c9c2e1 to your computer and use it in GitHub Desktop.
#
# Copyright 2012 Mortar Data Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# AWS status rss reader
#
# Publish a message in campfire whenever AWS publishes a new status update.
#
# Will only post each message once and will never post messages that are older than 1 hour.
fs = require('fs')
feedparser = require('feedparser');
room = process.env.HUBOT_CAMPFIRE_ROOMS
last_check_time = 0
oldest_date_to_post = (new Date()).getTime() - (60 * 60 * 1000)
poll_interval = 60 * 1000
get_callback = (robot, user) ->
parser_callback = (error, meta, articles) ->
if error
console.error(error)
else
now = (new Date()).getTime()
for article in articles
pubDate = Date.parse(article['pubdate'])
if (pubDate - last_check_time) >= 0 and (pubDate - oldest_date_to_post) >= 0
message = "@uhOh - #{article.guid} - #{article.title} \n #{article.description}"
robot.send user, message
last_check_time = now
return parser_callback
checkStatus = (robot) ->
user = robot.userForId 'Development'
user.room = room
out = feedparser.parseUrl("http://status.aws.amazon.com/rss/all.rss", get_callback(robot, user))
module.exports = (robot) ->
setInterval(checkStatus, poll_interval, robot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment