Skip to content
This repository
Aaron Ott October 27, 2012
file 32 lines (29 sloc) 0.973 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
# Description:
# Returns the weather from thefuckingweather.com
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot what's the weather for <city> - Get the weather for a location
# hubot what's the weather for <zip> - Get the weather for a zipcode
#
# Author:
# aaronott

weather = (msg, query, cb) ->
  msg.http('http://thefuckingweather.com/')
    .query(where: query)
    .header('User-Agent', 'Mozilla/5.0')
    .get() (err, res, body) ->
      temp = body.match(/<span class="temperature" tempf="\d*">(\d+)/)?[1] || ""
      remark = body.match(/<p class="remark">(.*)</)?[1] || "remark not found"
      flavor = body.match(/<p class="flavor">(.*)</)?[1] || "flavor not found"
      cb(temp, remark, flavor)

module.exports = (robot) ->
  robot.respond /(what's|what is) the weather for (.*)/i, (msg) ->
    weather msg, msg.match[2], (temp, remark, flavor) ->
      out = temp + " degrees " + remark + " " + flavor
      msg.send out
Something went wrong with that request. Please try again.