Last active
June 13, 2019 00:38
-
-
Save doneill/59ad517ee8509c262f8acc51ccb5ec5b to your computer and use it in GitHub Desktop.
Fulcrum data event to get current temp from openweathermap
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
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