From 412995ac096d21c48e0b26de70ebcef2d0eb276c Mon Sep 17 00:00:00 2001 From: Tapajyoti Bose <44058757+ruppysuppy@users.noreply.github.com> Date: Sun, 21 Jun 2020 22:08:29 +0530 Subject: [PATCH] Added Web-Programming (Open Weather Maps data fetch) (#196) * Added Web-Programming (Open Weather Maps data fetch) * update Co-authored-by: itsvinayak --- Sorts/{Heapsort.js => HeapSortV2.js} | 0 Web-Programming/OpenWeatherMaps.js | 31 ++++++++++++++++++++++++++++ package.json | 13 ++++++++++++ 3 files changed, 44 insertions(+) rename Sorts/{Heapsort.js => HeapSortV2.js} (100%) create mode 100644 Web-Programming/OpenWeatherMaps.js create mode 100644 package.json diff --git a/Sorts/Heapsort.js b/Sorts/HeapSortV2.js similarity index 100% rename from Sorts/Heapsort.js rename to Sorts/HeapSortV2.js diff --git a/Web-Programming/OpenWeatherMaps.js b/Web-Programming/OpenWeatherMaps.js new file mode 100644 index 000000000..7f1d4e31b --- /dev/null +++ b/Web-Programming/OpenWeatherMaps.js @@ -0,0 +1,31 @@ +const fetch = require('node-fetch') + +const APPID = '' // <-- Put your OpenWeatherMap appid here! +const URL_BASE = 'http://api.openweathermap.org/data/2.5/' + +async function currentWeather (location) { + const response = await fetch(`${URL_BASE}weather?q=${location}&appid=${APPID}`) + const data = await response.json() + return data +} + +async function weatherForecast (location) { + const response = await fetch(`${URL_BASE}forecast?q=${location}&appid=${APPID}`) + const data = await response.json() + return data +} + +async function oneCallApi (latitude, longitude) { + const response = await fetch(`${URL_BASE}onecall?lat=${latitude}&lon=${longitude}&appid=${APPID}`) + const data = await response.json() + return data +} + +currentWeather('Kolkata') + .then(data => console.log(data)) + +weatherForecast('Kolkata') + .then(data => console.log(data)) + +oneCallApi(55.68, 12.57) + .then(data => console.log(data)) diff --git a/package.json b/package.json new file mode 100644 index 000000000..f52472823 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "javascript", + "version": "1.0.0", + "description": "A repository for All algorithms implemented in Javascript (for educational purposes only)", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "TheAlgorithms", + "license": "GPL-3.0", + "dependencies": { + "node-fetch": "2.6.0" + } +} \ No newline at end of file