File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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();
You can’t perform that action at this time.
0 commit comments