From a4c6807c2818696ecd8644973c60d89fc1ced6b9 Mon Sep 17 00:00:00 2001 From: Adam Guyot Date: Thu, 10 Oct 2013 21:40:37 -0400 Subject: [PATCH 1/2] adding jwz feed puller --- src/scripts/jwz.coffee | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/scripts/jwz.coffee diff --git a/src/scripts/jwz.coffee b/src/scripts/jwz.coffee new file mode 100644 index 000000000..3ad04556d --- /dev/null +++ b/src/scripts/jwz.coffee @@ -0,0 +1,75 @@ +# Description: +# JWZ Blog Feed +# +# Dependencies: +# "nodepie": "0.5.0" +# +# Configuration: +# None +# +# Commands: +# hubot jwz last - get the last N posts +# +# Notes: +# We make an assumption that the video is youtube, not always true, plz2bfixing +# Stolen from the hackernews.coffee script +# +# Author: +# MonkeyIsNull + +NodePie = require("nodepie") +Cheerio = require("cheerio") + +jwzFeedUrl = "http://www.jwz.org/blog/feed/" + + +module.exports = (robot) -> + robot.respond /JWZ last (\d+)?/i, (msg) -> + msg.http(jwzFeedUrl).get() (err, res, body) -> + if res.statsCode is not 200 + msg.send "Oh my, something has gone dreadfully wrong" + else + feed = new NodePie(body) + try + feed.init() + count = msg.match[1] || 5 + items = feed.getItems(0, count) + for item in items + $ = Cheerio.load(item.getContents()) + msg.send false_cleaner(item.getTitle()) + desc_cleaner(item.getDescription()) + get_first($) + catch e + console.log(e) + msg.send "Jinkies, apparently there has been a problem!" + +# All these are utils for cleaning up the garbled results +false_cleaner = (data) -> + if data is false + " " + else + data + +desc_cleaner = (data) -> + if data is false + " " + else + " ( #{data}) " + +undef_cleaner = (data) -> + if data is undefined + return " " + data + +not_a_previously_link = ($) -> + if $('a').first().html() == "Previously" + return undefined + else + return $('a').first().attr('href') + +get_first = ($) -> + link = not_a_previously_link($) + vid = $('iframe').first().attr('src') + if vid == undefined + undef_cleaner(link) + else # uhoh, we are making an assumption here that it's youtube, bad bad! + vid2 = "http://www.youtube.com/watch?v=" + $('iframe').first().attr('src').match(/r?embed\/(.*)\?/)[1] + undef_cleaner(link) + " " + vid2 From 32273a578d143f2ec16e4a1a0c6bec3c06e6210e Mon Sep 17 00:00:00 2001 From: Adam Guyot Date: Thu, 10 Oct 2013 21:43:22 -0400 Subject: [PATCH 2/2] adding rcs feed puller --- src/scripts/rcst.coffee | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/scripts/rcst.coffee diff --git a/src/scripts/rcst.coffee b/src/scripts/rcst.coffee new file mode 100644 index 000000000..39d62fca6 --- /dev/null +++ b/src/scripts/rcst.coffee @@ -0,0 +1,41 @@ +# Description: +# Riot Clit Shave Tmblr Picture Feed - Sometimes NSFW +# +# Dependencies: +# "nodepie": "0.5.0" +# +# Configuration: +# None +# +# Commands: +# hubot rcst last - get the last N posts from rcs' tumblr feed +# +# Notes: +# Stolen from the hackernews.coffee script +# +# Author: +# MonkeyIsNull + +NodePie = require("nodepie") +Cheerio = require("cheerio") + +rcstFeedUrl = "http://riotclitshave.tumblr.com/rss" + +module.exports = (robot) -> + robot.respond /RCST last (\d+)?/i, (msg) -> + msg.http(rcstFeedUrl).get() (err, res, body) -> + if res.statsCode is not 200 + msg.send "Oh dear, something went wrong" + else + feed = new NodePie(body) + try + feed.init() + count = msg.match[1] || 5 + items = feed.getItems(0, count) + for item in items + $ = Cheerio.load(item.getDescription()) + $('img').each ( ) -> + msg.send $(this).attr('src') + catch e + console.log(e) + msg.send "Something has gone horribly wrong, yo!"