Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Forecast

node v4.9.1
version: 1.0.0
endpointsharetweet
require("request"); // peer dependency var request = require('request-promise'); var _ = require('lodash'); var url = require('url'); var apiKey = process.env.OPENWEATHERMAP_KEY; function temperatureURL(city) { return url.format({ protocol: "http", host: "api.openweathermap.org", pathname: "data/2.5/forecast", query: {units: "imperial", mode: "json", q: city, APPID: apiKey} }); } async function threeDay(city) { if (!apiKey) { throw `<div> <h2>Whoops!</h2> <p>You need an API key to use this service. Sign up at <a href="http://home.openweathermap.org/users/sign_up"> openweathermap.org</a>, and grab your API key:<br /><br /> <img src="http://bit.ly/1GgoJZm" width="500" /></p> <p>Now, add <code>OPENWEATHERMAP_KEY</code> to your <a href="https://tonicdev.com/settings/environment"> environment settings</a>:<br /><br /> <img src="http://bit.ly/1kmRPfQ" width="500" /></p> </div>` } var response = await request(temperatureURL(city)); return _.map(JSON.parse(response)['list'], function(entry) { return entry["main"]["temp"]; }); }; module.exports = { threeDay: threeDay };
Exports a utility function to grab a 3 day weather forecast from openweathermap.org.
Loading…

no comments

    sign in to comment