Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (40 sloc) 1.414 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 37 38 39 40 41 42 43 44 45
# Description:
# It's very important to know the cutoff date for switching from hot
# coffee to iced coffee. This script does just that.
#
# Dependencies:
# "cheerio": "0.7.0"
#
# Configuration:
# HUBOT_ICED_COFFEE_WEATHER_ID
#
# Commands:
# hubot is it iced coffee weather? - Display whether or not it's a good time for iced coffee
#
# Notes:
# Go to http://isiticedcoffeeweather.com/
# Allow it to detect your location, or enter it yourself
# Look at the URL, ie http://isiticedcoffeeweather.com/XXXXXXXX
# XXXXXXXX is the id
#
# Author:
# technicalpickles

cheerio = require('cheerio')

iced_coffee_weather_id = process.env.HUBOT_ICED_COFFEE_WEATHER_ID

module.exports = (robot) ->
  robot.respond /is it iced (coffee|latte) weather/i, (msg) ->
    if ! iced_coffee_weather_id
      msg.send "I don't know where you are, so I can't say. Make sure to set HUBOT_ICED_COFFEE_WEATHER_ID"
      return

    url = "http://isiticedcoffeeweather.com/#{iced_coffee_weather_id}"
    msg
      .http(url)
      .header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6')
      .get() (err, res, body) ->
        if err
          msg.send "Something went wrong #{err}"
          return
        msg.send "my sources say #{getIcedCoffe body} #{url}"

getIcedCoffe = (body, callback) ->
 $ = cheerio.load(body)
 $('body h2').text()
Something went wrong with that request. Please try again.