Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 37 lines (31 sloc) 0.899 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# Description:
# When in Austin
#
# Dependencies:
# "jsdom": "0.2.14"
#
# Configuration:
# None
#
# Commands:
# hubot when in austin - Pull a random entry from wheninatx.tumblr.com
#
# Author:
# elliotttf

http = require 'http'
jsdom = require 'jsdom'

module.exports = (robot) ->
  robot.respond /when(\s)?in(\s)?austin/i, (msg) ->
    options =
      host: 'wheninatx.tumblr.com',
      port: 80,
      path: '/random'

    # Random redirects us to another article, grab that url and respond.
    http.get options, (res) ->
      location = res.headers.location
      jsdom.env location, [ 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' ], (errors, window) ->
        (($) ->
          title = $('meta[property="og:title"]').attr('content')
          img = $('article p[align="center"] img').attr('src')

          msg.send title + ' ' + img
        )(window.jQuery)

Something went wrong with that request. Please try again.