Skip to content

Commit 412995a

Browse files
Added Web-Programming (Open Weather Maps data fetch) (TheAlgorithms#196)
* Added Web-Programming (Open Weather Maps data fetch) * update Co-authored-by: itsvinayak <itssvinayak@gmail.com>
1 parent 78262df commit 412995a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
File renamed without changes.

Web-Programming/OpenWeatherMaps.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fetch = require('node-fetch')
2+
3+
const APPID = '' // <-- Put your OpenWeatherMap appid here!
4+
const URL_BASE = 'http://api.openweathermap.org/data/2.5/'
5+
6+
async function currentWeather (location) {
7+
const response = await fetch(`${URL_BASE}weather?q=${location}&appid=${APPID}`)
8+
const data = await response.json()
9+
return data
10+
}
11+
12+
async function weatherForecast (location) {
13+
const response = await fetch(`${URL_BASE}forecast?q=${location}&appid=${APPID}`)
14+
const data = await response.json()
15+
return data
16+
}
17+
18+
async function oneCallApi (latitude, longitude) {
19+
const response = await fetch(`${URL_BASE}onecall?lat=${latitude}&lon=${longitude}&appid=${APPID}`)
20+
const data = await response.json()
21+
return data
22+
}
23+
24+
currentWeather('Kolkata')
25+
.then(data => console.log(data))
26+
27+
weatherForecast('Kolkata')
28+
.then(data => console.log(data))
29+
30+
oneCallApi(55.68, 12.57)
31+
.then(data => console.log(data))

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "javascript",
3+
"version": "1.0.0",
4+
"description": "A repository for All algorithms implemented in Javascript (for educational purposes only)",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"author": "TheAlgorithms",
9+
"license": "GPL-3.0",
10+
"dependencies": {
11+
"node-fetch": "2.6.0"
12+
}
13+
}

0 commit comments

Comments
 (0)