diff --git a/README.md b/README.md index 1e4fa33..41fa558 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ +[![License](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Community](https://img.shields.io/badge/Join-Community-blue.svg)](https://developer.ibm.com/callforcode/solutions/projects/get-started/) + # Weather Company Data API access for IBM Cloud This project shows how to build a basic data access application that continuously runs in the background, processing a variety of weather data from the Weather Company Data for IBM REST API endpoints, including severe weather alerts, tropical storm forecasts, and the daily weather almanac to find conditions over time. ## Obtain a Weather Company API Key -If you're participating in the [Call for Code](https://developer.ibm.com/callforcode/) Global Challenge, go the the [special Call for Code Weather web site](https://callforcode.weather.com/) and [register](https://callforcode.weather.com/register). A time-limited API key will be sent to you via email. The documentation for the Weather Company APIs for Call for Code can be found the [here](https://callforcode.weather.com/documentation/). +If you are participating in the [Call for Code](https://developer.ibm.com/callforcode/solutions/projects/get-started/) Global Challenge, request access to [The Weather Company APIs](https://developer.ibm.com/callforcode/tools/weather/). Registration is free and will be available while the Call for Code Global Challenge is taking place. After you agree to the terms, you will receive your API key. Additional documentation about The Weather Company APIs for Call for Code is available [here](https://developer.ibm.com/blogs/call-for-code-the-weather-company-and-you/). ## Getting Started in IBM Cloud @@ -15,7 +17,7 @@ Deploy this application to IBM Cloud. ``` $ git clone https://github.com/Call-for-Code/weather-api-nodejs.git $ cd weather-api-nodejs - ``` + ``` 3. Deploy the application without starting it ``` $ ibmcloud cf push --no-start @@ -34,22 +36,21 @@ To run this application on your local machine, first install Node.js. ``` $ git clone https://github.com/Call-for-Code/weather-api-nodejs.git $ cd weather-api-nodejs - ``` + ``` 2. Install the dependencies ``` $ npm install ``` -3. Set your Weather API key `` when running the application +3. Set your Weather API key `` when running the application ``` $ WEATHER_API_KEY= node app.js ``` ## Links -[Call for Code](https://callforcode.org/) -[Call for Code - IBM Developer](https://developer.ibm.com/callforcode/) -[Call for Code - The Weather Company](https://callforcode.weather.com/) -[Call for Code: The Weather Company and you](https://developer.ibm.com/callforcode/blogs/call-for-code-the-weather-company-and-you/) +- [Call for Code](https://callforcode.org/) +- [Call for Code - IBM Developer](https://developer.ibm.com/callforcode/) +- [Call for Code: The Weather Company and you](https://developer.ibm.com/callforcode/blogs/call-for-code-the-weather-company-and-you/) ## License diff --git a/lib/daily-forecast.js b/lib/daily-forecast.js index a7876b4..7c0896b 100644 --- a/lib/daily-forecast.js +++ b/lib/daily-forecast.js @@ -1,7 +1,7 @@ /** * Daily Forecast * - * - https://weather.com/swagger-docs/ui/sun/v1/sunV1DailyForecast.json + * - https://ibm.co/V3DFap * * The daily forecast API returns the geocode weather forecasts for the current day * up to the days duration in the API endpoint. The daily forecast product can contain @@ -9,37 +9,40 @@ * contain up to (3) “temporal segments” meaning three separate forecasts. For any * given forecast day we offer day, night, and a 24-hour forecast (daily summary). * - * Base URL: api.weather.com/v1 - * Endpoint: /geocode/{latitude}/{longitude}/forecast/daily/{days}day.json + * Base URL: api.weather.com/v3 + * Endpoint: /wx/forecast/daily/15day */ const apiUtil = require('./api-util') -exports.requestOptions = function (lat, lon, days = 3, units = 'm') { - const d = [3, 5, 7, 10, 15].indexOf(days) === -1 ? 3 : days +exports.requestOptions = function (lat, lon, days = 15, units = 'm') { + const d = [3, 5, 7, 10, 15].indexOf(days) === -1 ? 15 : days const u = ['e', 'm', 'h', 's'].indexOf(units) === -1 ? 'm' : units let options = apiUtil.defaultParams() - options['uri'] = `${apiUtil.HOST}/v1/geocode/${lat}/${lon}/forecast/daily/${d}day.json` options.qs['units'] = u + let urlparams="&format=json&units="+options.qs['units']+"&language="+options.qs['language']+"&apiKey="+options.qs['apiKey'] + options['url'] = `${apiUtil.HOST}/v3/wx/forecast/daily/${d}day?geocode=${lat},${lon}`+urlparams + //console.log( options ); return options } exports.handleResponse = function (res) { - if (res && res.hasOwnProperty('forecasts')) { - const forecasts = res.forecasts - console.log(`daily-forecast: returned ${forecasts.length}-day forecast`) + if (res && res.hasOwnProperty('narrative')) { + const forecasts = res + console.log(`daily-forecast: returned ${forecasts.dayOfWeek.length}-day forecast`) - // each entry in the forecasts array corresponds to a daily forecast - forecasts.forEach(daily => { - console.log(`daily-forecast: day ${daily.num} - High of ${daily['max_temp']}, Low of ${daily['min_temp']}`) - console.log(`daily-forecast: day ${daily.num} - ${daily.narrative}`) - }) + // Parse responses + for( num=0; num NPM_CONFIG_PRODUCTION: false - buildpack: sdk-for-nodejs + buildpack: https://github.com/cloudfoundry/nodejs-buildpack diff --git a/package-lock.json b/package-lock.json index 35c62f0..9af007a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -173,11 +173,6 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" - }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -189,20 +184,27 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", - "json-schema": "0.2.3", + "json-schema": "0.4.0", "verror": "1.10.0" + }, + "dependencies": { + "json-schema": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==" + } } }, "lodash": { - "version": "4.17.19", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", - "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==" + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "mime-db": { "version": "1.44.0", @@ -238,9 +240,9 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", + "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==" }, "request": { "version": "2.88.2",