From 0e9827a2fc18e9d482f3032333c726e62b6adf5b Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 12:38:27 +0000 Subject: [PATCH] further development was precipitated --- modules/rain/rain.js | 19 ++++++++++++++----- modules/rain/strings.json | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/rain/rain.js b/modules/rain/rain.js index c6f2165..5af0b5c 100644 --- a/modules/rain/rain.js +++ b/modules/rain/rain.js @@ -9,11 +9,20 @@ var rain = function(dbot) { var commands = { '~rain': function(event) { var apikey = dbot.config.rain.apikey; - var precip = event.params[1]; - var score = 2 * Math.pow(precip,0.5); - score = Math.ceil(score); - if (score > 10) { score = 11; } - event.reply(dbot.t("rain-"+score)); + var place = "Aberystwyth"; // you probably need to change the formulae if you change location + var url = "http://api.wunderground.com/api/" + apikey + "/conditions/q/CA/" + place + ".json"; + request(url, function(error, response, body) { + if(response.statusCode == "200") { + var data = JSON.parse(body); + var precip = data["precip_1hr_metric"]; + var score = 2 * Math.pow(precip,0.5); + score = Math.ceil(score); + if (score > 10) { score = 11; } + } else { + var score = "e"; + } + event.reply(dbot.t("rain-"+score+"[ " + score + " ]")); + }); } }; diff --git a/modules/rain/strings.json b/modules/rain/strings.json index 5100e0b..bd5a5a2 100644 --- a/modules/rain/strings.json +++ b/modules/rain/strings.json @@ -34,5 +34,8 @@ }, "rain-11": { "english" : "LOL U PROBABLY DIED" + }, + "rain-e": { + "english" : "Unable to fetch weather data." } }