Skip to content

Commit 4aa89d2

Browse files
authored
Create DataFunction.js
1 parent e76bf45 commit 4aa89d2

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const WEATHER_API = "be43bb35b1dde85b62d0f3f123cb751f";
2+
3+
const getData = async (url) => {
4+
const dataJson = await fetch(url);
5+
const data = await dataJson.json();
6+
return data;
7+
};
8+
9+
export const getDataFromApi = async (WeatherObj) => {
10+
const url = `https://api.openweathermap.org/data/2.5/weather?q=${
11+
WeatherObj.location || "Mumbai"
12+
}&units=metric&appid=${WEATHER_API}`;
13+
const locationObj = await getData(url);
14+
WeatherObj.temp = locationObj.main.temp;
15+
WeatherObj.humidity = locationObj.main.humidity;
16+
WeatherObj.wind = locationObj.wind.speed;
17+
WeatherObj.icon = locationObj.weather[0].icon;
18+
// console.log(WeatherObj.temp);
19+
// console.log(WeatherObj.humidity);
20+
// console.log(WeatherObj.wind);
21+
// console.log(WeatherObj.icon);
22+
// console.log(locationObj);
23+
};
24+
25+
// await (await fetch("https://api.openweathermap.org/data/2.5/weather?q=London&units=metric&appid=be43bb35b1dde85b62d0f3f123cb751f")).json();

0 commit comments

Comments
 (0)