Created
October 19, 2020 20:27
-
-
Save Cvetomird91/c3c36dc3523790500e06d5f85b3f5a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("https"); | |
const options = { | |
"method": "GET", | |
"hostname": "rapidapi.p.rapidapi.com", | |
"port": null, | |
// "path": "/forecast/daily?q=san%20francisco%2Cus&lat=35&lon=139&cnt=16", | |
"path": "/forecast/daily?q=london%2Cuk&lat=35&lon=139&cnt=16", | |
"headers": { | |
"x-rapidapi-host": "community-open-weather-map.p.rapidapi.com", | |
"x-rapidapi-key": "f12c80e64bmshaced9840c9776cbp1d9bb0jsn0219aef0ce39", | |
"useQueryString": true | |
} | |
}; | |
const req = http.request(options, async function (res) { | |
const chunks = []; | |
res.on("data", function (chunk) { | |
chunks.push(chunk); | |
}); | |
res.on("end", function () { | |
const body = Buffer.concat(chunks); | |
const responseObject = JSON.parse(body.toString()); | |
//1. | |
const filtered = responseObject.list.filter((element) =>{ | |
return element.clouds > 65; | |
}); | |
const shortHandInformation = []; | |
//2. | |
filtered.forEach(elem => { | |
let temp = { | |
pressure: elem.pressure, | |
rain: elem.rain, | |
speed: elem.speed, | |
}; | |
shortHandInformation.push(temp); | |
}); | |
console.log(shortHandInformation); | |
let speedMean = 0; | |
shortHandInformation.forEach(elem => { | |
speedMean += elem.speed; | |
}); | |
speedMean = speedMean / shortHandInformation.length; | |
console.log(speedMean); | |
//3. | |
const weatherClouds = responseObject.list.filter((element) =>{ | |
return element.weather[0].main === "Clouds"; | |
}); | |
console.log(weatherClouds); | |
const weatherCloudsData = []; | |
weatherClouds.forEach(element => { | |
let temp = { | |
description: element.weather[0].description, | |
icon: element.weather[0].icon, | |
id: element.weather[0].id, | |
}; | |
weatherCloudsData.push(temp); | |
}); | |
console.log(weatherCloudsData); | |
}); | |
}); | |
req.end(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment