Last active
August 29, 2015 13:58
-
-
Save AbhiAgarwal/9997386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gets Weather from the ForecastIO API and saves the JSON file | |
var set_weather = function() { | |
jquery.getJSON('https://api.forecast.io/forecast/'+ apiKeys.forecastIO + '/' + person.latitude + ',' + person.longitude, function(data) { | |
fs.writeJson('./files/weather' + datetime + '.json', data, function(err){ | |
if(err){ console.log(err);} | |
weather.time = datetime; | |
weather.summary = data.currently.summary; | |
weather.temperature = String(convert_fahrenheitTocelsius(String(data.currently.temperature))); | |
weather.file = true; | |
}); | |
}); | |
}; | |
// Geather from the JSON file | |
var get_weather = function() { | |
fs.readJson('./files/weather' + datetime + '.json', function(err, data) { | |
if(err){ | |
set_weather(); | |
} else { | |
weather.time = datetime; | |
weather.summary = data.currently.summary; | |
weather.temperature = String(convert_fahrenheitTocelsius(String(data.currently.temperature))); | |
weather.file = true; | |
} | |
}); | |
}; | |
// Applications Function | |
// Gets weather from Forecast.IO API, or JSON file and says it | |
var say_getWeather = function() { | |
if(weather.summary == ""){ | |
get_weather(); | |
} else { | |
say.speak(person.speaker, "In Bangkok there is a chance of " | |
+ String(weather.summary) | |
+ " , with a temperature of " | |
+ String(weather.temperature) | |
+ "Celcius" | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment