-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforcast.js
More file actions
37 lines (23 loc) · 827 Bytes
/
forcast.js
File metadata and controls
37 lines (23 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//API from https://www.developer.accuweather.com
const key = 'BHJZVeiEt2WBGH42HPot5SmGvHG2fwaA';
const getWeather = async id => {
const baseUrl = 'http://dataservice.accuweather.com/currentconditions/v1/';
const queryParam = `${id}?apikey=${key}`;
const response = await fetch(baseUrl + queryParam);
const data = await response.json();
return data[0];
}
const getCity = async city => {
baseUrl = 'http://dataservice.accuweather.com/locations/v1/cities/search';
queryParam = `?apikey=${key}&q=${city}`;
const response = await fetch(baseUrl + queryParam);
const data = await response.json();
return data[0];
}
// getCity('china')
// .then(data => {
// return getWeather(data.Key)
// }).then( data =>{
// console.log(data);
// })
// .catch(err => console.log(err))