Skip to content

Instantly share code, notes, and snippets.

@scottfinkelstein
Created March 23, 2015 12:17
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 scottfinkelstein/bfa262c57198a6d00acc to your computer and use it in GitHub Desktop.
Save scottfinkelstein/bfa262c57198a6d00acc to your computer and use it in GitHub Desktop.
Scriptr.io Email Weather Script
// 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