From 119f48dcca6a9422e7994e59cd143e165a681c52 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Sat, 25 Apr 2015 18:58:11 +0200 Subject: [PATCH] implementato meteo, fix #5 --- scripts/meteo.coffee | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/meteo.coffee b/scripts/meteo.coffee index d08db05..bacdbb8 100644 --- a/scripts/meteo.coffee +++ b/scripts/meteo.coffee @@ -2,7 +2,7 @@ # utilità per il meteo # # Dependencies: -# None +# "moment":"2.10.2" # # Configuration: # None @@ -13,6 +13,20 @@ # Author: # Enrico Fasoli (fazo96) +moment = require 'moment' + module.exports = (robot) -> robot.respond /che tempo(?: c'è| fa)?(?: a crema)?(?:\?)?/i, (res) -> - res.send moment().format('dddd Do MMMM YYYY H:MM:SS') + url = 'http://api.openweathermap.org/data/2.5/weather?id=3177841&lang=it&units=metric' + robot.http(url) + .get() (err, r, body) -> + try + body = JSON.parse body + catch e + return res.send 'errore nel guardare il cielo.' + alba = moment.unix(body.sys.sunrise).format('H:MM') + tramonto = moment.unix(body.sys.sunset).format('H:MM') + m = body.weather[0].description+' con '+body.main.humidity + m += '% di umidità. Temperatura: '+body.main.temp+'°C. ' + m += "l'alba è alle "+alba+" mentre il tramonto alle "+tramonto + res.send 'Meteo per Crema: '+m+'.'