Created
March 23, 2015 12:17
-
-
Save scottfinkelstein/bfa262c57198a6d00acc to your computer and use it in GitHub Desktop.
Scriptr.io Email Weather Script
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
// Include http module | |
var http=require('http'); | |
// Get the ZIP code and email passed in by the request parameter sent to this script. | |
var zipCode=request.parameters.zipcode; | |
var email=request.parameters.email; | |
// Construct REST call to OpenWeatherMap API | |
var weatherService='http://api.openweathermap.org/data/2.5/weather?q='+zipCode+'&units=imperial'; | |
var callResult=http.request({'url': weatherService}); | |
// Convert returned JSON object to JavaScript object | |
var weatherInfo=JSON.parse(callResult.body); | |
var temperature=weatherInfo.main.temp; | |
var locationName=weatherInfo.name; | |
// Create email configuration object | |
var emailConfig={ | |
'to': email, | |
'fromName': 'Scott', | |
'subject': 'Current Weather Conditions', | |
'body': 'It is currently '+temperature+' degrees in '+locationName | |
}; | |
// run sendMail method to send email via scriptr.io and return response. | |
return sendMail(emailConfig.to, emailConfig.fromName, emailConfig.subject, emailConfig.body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment