-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
237 lines (216 loc) · 7.67 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSdUijW8Pl6X57WSf5jgv0q00gtqFw0w0saJw&usqp=CAU">
<title>weather</title>
<style>
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
background-image: url("https://www.maketecheasier.com/assets/uploads/2020/06/Featured-Image-Live-Weather-Wallpapers-Android.jpg");
}
#main {
display: grid;
grid-template-columns: repeat(12, 1fr);
/* grid-template-rows: 200px; */
grid-gap: 10px;
grid-template-areas:
"d d d d d d d d d d d d"
"a a a a b b b b b b b b"
"c c c c c c c c c c c c";
padding: 10px;
}
#climate {
grid-area: a;
/* background-color: yellow; */
padding: 0px 40px;
}
#map {
grid-area: b;
/* display: none; */
/* background-color: green; */
}
/* #wheaterData img{
} */
#dailyWheater {
grid-area: c;
/* background-color: rgb(177, 239, 243); */
border-radius: 30px;
}
#searchBar {
grid-area: d;
/* background-color: rgb(177, 239, 243); */
text-align: center;
}
#dailyWheater {
display: grid;
grid-template-columns: repeat(5, 1fr);
/* grid-template-rows: 200px; */
grid-gap: 10px;
width: 60%;
margin: auto;
padding: 10px;
}
#dailyWheater div {
background-color: rgba(196, 221, 214, 0.432);
text-align: center;
border-radius: 30px;
padding: 10px;
}
#search {
width: 350px;
height: 30px;
border-radius: 20px;
border: 1px solid gainsboro;
padding: 10px;
}
#searchbtn {
height: 30px;
border-radius: 20px;
padding: 5px 40px;
border: 0px;
margin-left: 40px;
}
#searchbtn:hover {
background-color: rgb(247, 214, 166);
cursor: pointer;
}
#wheaterData{
color: rgb(255, 255, 255);
font-size: 20px;
}
#wheaterData p{
background-color: rgba(231, 216, 200, 0.397);
border-radius: 10px;
margin: 3px 0px;
padding: 5px 5px;
}
#gmap_canvas{
display: none;
}
li{
margin-left: 30px;
}
</style>
</head>
<body>
<div id="main">
<div id="searchBar">
<form action="">
<input type="text" id="search" placeholder="Please Enter City Name" />
<input
type="button"
onclick="getData()"
value="Search"
id="searchbtn"
/>
</form>
</div>
<div id="climate">
<div id="wheaterData"></div>
</div>
<div id="map">
<div class="gmap_canvas">
<iframe
width="100%"
height="400"
id="gmap_canvas"
src="https://maps.google.com/maps?&t=&z=13&ie=UTF8&iwloc=&output=embed"
frameborder="0"
scrolling="no"
marginheight="0"
marginwidth="0"
></iframe
><a href="https://123movies-a.com"></a><br />
</div>
</div>
<div id="dailyWheater"></div
</div>
</body>
</html>
<script>
async function getData() {
var climateCity = document.querySelector("#search").value;
var climate_API_Key = "5afbdb191732e7c2cecddb62cbe72358";
var climateURL = `https://api.openweathermap.org/data/2.5/weather?q=${climateCity}&appid=${climate_API_Key}&units=metric`;
var num = 7;
var dailyWheaterURL = `https://api.openweathermap.org/data/2.5/forecast/daily?q=${climateCity}&cnt=${num}&appid=${climate_API_Key}`;
var mapURL = `https://maps.google.com/maps?q=${climateCity}&t=&z=13&ie=UTF8&iwloc=&output=embed`;
var climateDailyURL = `https://api.openweathermap.org/data/2.5/forecast?q=${climateCity}&appid=${climate_API_Key}&units=metric`;
document.querySelector("#gmap_canvas").style.display="block"
try {
let res = await fetch(climateURL);
let data = await res.json();
// console.log(data);
displayClimateData(data);
displayMapData(climateCity);
let res1 = await fetch(climateDailyURL);
let data1 = await res1.json();
data1 = data1.list;
var dataArray = [];
for (i = 2; i < data1.length; i = i + 8) {
dataArray.push(data1[i]);
}
console.log(dataArray);
displayClimateDailyData(dataArray);
// let res1 = await fetch("dailyWheaterURL");
// let data1 = await res1.json();
// console.log(data1);
} catch (err) {
console.log("server is not");
}
}
function displayMapData(climateCity) {
document.querySelector(
"#gmap_canvas"
).src = `https://maps.google.com/maps?q=${climateCity}&t=&z=13&ie=UTF8&iwloc=&output=embed`;
}
function displayClimateData(elem) {
document.querySelector("#wheaterData").innerHTML = "";
var div = document.createElement("div");
var p1 = document.createElement("p");
p1.innerHTML = `City Name:-${elem.name}`;
var p2 = document.createElement("p");
p2.innerHTML = `Minimum Temperature:-${elem.main.temp_min}°C`;
var p3 = document.createElement("p");
p3.innerHTML = `Maximum Temperature:-${elem.main.temp_max}°C`;
var p4 = document.createElement("p");
p4.innerHTML = `Wind:-<ul><li>deg:${elem.wind.deg} degrees</li><li>gust:${elem.wind.gust} meter/sec</li><li>speed:${elem.wind.speed} meter/sec</li></ul>`;
var p5 = document.createElement("p");
var link = `https://openweathermap.org/img/wn/${elem.weather[0].icon}@2x.png`;
p5.innerHTML = `Clouds:-${elem.weather[0].description} <br> <img src=${link} width=50px >`;
var p6 = document.createElement("p");
p6.innerHTML = `Sunrise:-${new Date(
elem.sys.sunrise * 1000
).toLocaleTimeString()} <sub><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTpFHZcs7IrYk1qEit-dFItwqXyCYmUvAkakQPepOPtdsoZmsJRRFaa-oXqcNKFtEFGclo&usqp=CAU" height=22px width=40px style="border-radius: 20px;"/></sub>`;
var p7 = document.createElement("p");
p7.innerHTML = `Sunset:-${new Date(
elem.sys.sunset * 1000
).toLocaleTimeString()} <sub><img src="https://upload.wikimedia.org/wikipedia/commons/9/9e/PG_SUNSET.png" width=40px height=22px style="border-radius: 20px;"/></sub>`;
div.append(p1, p2, p3, p4, p5, p6, p7);
document.querySelector("#wheaterData").append(div);
}
function displayClimateDailyData(data) {
document.querySelector("#dailyWheater").innerHTML = "";
data.map((elem) => {
var div = document.createElement("div");
var h5 = document.createElement("h5");
h5.innerHTML = `${new Date(elem.dt * 1000).toLocaleDateString()}`;
var p2 = document.createElement("p");
p2.innerHTML = `${elem.main.temp_min}°C`;
var p3 = document.createElement("p");
p3.innerHTML = `${elem.main.temp_max}°C`;
var p5 = document.createElement("p");
var link = `https://openweathermap.org/img/wn/${elem.weather[0].icon}@2x.png`;
p5.innerHTML = `<img src=${link} width=50px >`;
div.append(h5, p5, p3, p2);
document.querySelector("#dailyWheater").append(div);
});
}
</script>