Skip to content

Instantly share code, notes, and snippets.

@doneill
Last active June 13, 2019 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doneill/59ad517ee8509c262f8acc51ccb5ec5b to your computer and use it in GitHub Desktop.
Save doneill/59ad517ee8509c262f8acc51ccb5ec5b to your computer and use it in GitHub Desktop.
Fulcrum data event to get current temp from openweathermap
var ow_appid = [APPID];
var ow_base_url = 'https://api.openweathermap.org';
var ow_api = '/data/2.5';
// changed event
ON('click', 'get_current_temp', getWeather);
// get open weather summary
function getWeather() {
var api_weather = '/weather?units=imperial&lat=';
var options = {
url: ow_base_url + ow_api + api_weather + LATITUDE() + '&lon=' + LONGITUDE() +'&appid=' + ow_appid
};
REQUEST(options, function(error, response, body) {
if (error) {
ALERT('Error with request: ' + error);
} else {
var main = JSON.parse(body).main;
SETVALUE('current_temp', main.temp + '° F');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment