-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherdemo.html
107 lines (82 loc) · 2.22 KB
/
weatherdemo.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<HTML>
<BODY>
<style>
table, td {
border: 1px solid black;
}
</style>
<div id="holder"></div>
<table id="myTable">
<tr>
<td>NAME</td>
<td>TEMP in celcius</td>
<td>PRESSURE</td>
<td>HUMIDITY</td>
<td>CLIMATE</td>
</table>
<SCRIPT>
//const fetch = require("node-fetch");
var apikey = "7f2afff39600342362600e39a9624a9c"
var contries = fetch("https://restcountries.eu/rest/v2/all")
.then((response) => {
return response.json();
})
.then((data) => {
//console.log(data);
var table = document.getElementById("myTable");
for(let i in data){
var key = i;
var val = data[i];
for(let j in val){
var sub_key = j;
var sub_val = val[j];
if(sub_key == "capital" && sub_val !="")
{
var country = sub_val;
fullurl = "http://api.openweathermap.org/data/2.5/weather?q="+country+"&units=metric&appid="+apikey;
//https://cors-anywhere.herokuapp.com/
console.log(fullurl);
fetch(fullurl)
.then((response)=>{
return response.json();
//var rest = JSON.stringify(rest1)
//console.log(rest);
}).then((rest)=>{
console.log(rest.main.temp);
var row = table.insertRow();
var cell0 = row.insertCell(0);
cell0.style.width = "1000px";
cell0.innerHTML =data[i].capital;
var img = document.createElement('img');
img.src = data[i].flag;
img.style.width="150px";
img.style.height="150px";
cell0.appendChild(img);
var cell1 = row.insertCell(1);
cell1.style.width = "1000px";
cell1.innerHTML =rest.main.temp;
var cell2 = row.insertCell(2);
cell2.style.width = "1000px";
cell2.innerHTML = rest.main.pressure;
var cell3 = row.insertCell(3);
cell3.style.width = "1000px";
cell3.innerHTML = rest.main.humidity;
var cell4 = row.insertCell(4);
cell4.style.width = "1000px";
cell4.innerHTML = rest.weather[0].main;
})
.catch((err)=>{
console.log(err);
})
}
//http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22
}
}
})
//})
//.then((countryname)=>{
// console.log(countryname);
//})
</SCRIPT>
</BODY>
</HTML>