Added Web-Programming (Open Weather Maps data fetch) (#196)

* Added Web-Programming (Open Weather Maps data fetch)

* update

Co-authored-by: itsvinayak <itssvinayak@gmail.com>
This commit is contained in:
Tapajyoti Bose
2020-06-21 22:08:29 +05:30
committed by GitHub
parent 78262df0a2
commit 412995ac09
3 changed files with 44 additions and 0 deletions

View File

@ -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))

13
package.json Normal file
View File

@ -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"
}
}