Created
September 11, 2019 23:12
-
-
Save caseysoftware/1519ea40d6586e7f01e9b89ba20f2a3b to your computer and use it in GitHub Desktop.
Retrieve Weather Data from Open Weather - https://openweathermap.org
This file contains hidden or 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
exports.handler = function( event, context ) { | |
var https = require( 'https' ); | |
var url = 'https://api.openweathermap.org/data/2.5/forecast?zip=78745,us&APPID=****APIKEY****' | |
https.get( url, function( response ) { | |
var data = ''; | |
response.on( 'data', function( x ) { data += x; } ); | |
response.on( 'end', function() { | |
var json = JSON.parse( data ); | |
var weather = json.list[0]; | |
var temp = weather.main.temp; | |
temp = (temp - 273.15) * 9/5 + 32; | |
var desc = weather.weather[0].description; | |
var status = 'Currently it is ' + temp + ' degrees and ' + desc; | |
output( status, context ); | |
} ); | |
} ); | |
}; | |
function output( status, context ) { | |
var response = [{ | |
"type":"com.okta.identity.patch", | |
value: [{ | |
op: "add", | |
path: "/claims/weather", | |
value: status | |
}] | |
}, | |
{ | |
"type":"com.okta.access.patch", | |
value: [{ | |
op: "add", | |
path: "/claims/weather", | |
value: status | |
}] | |
}]; | |
var message = { "stockLookup": "executed" } | |
context.succeed( { commands: response, debugContext: message } ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment