-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.html
263 lines (220 loc) · 10.5 KB
/
weather.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!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="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" integrity="sha384-b6lVK+yci+bfDmaY1u0zE8YYJt0TZxLEAFyYSLHId4xoVvsrQu3INevFKo+Xir8e" crossorigin="anonymous">
<title>Document</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Poppins:100,200,300,400,500,600,700,800,900');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background-color: rgb(13, 13, 17);
}
.main-container {
border-radius: 5%;
top: 20px;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
background-color: rgb(7, 1, 1);
background: linear-gradient(45deg, rgb(0, 0, 0),#080505);
position: relative;
}
#inputBox{
max-width: 40vw;
}
.weather-card {
width: 400px;
min-width: 200px;
max-width: 400px;
border-radius: 5%;
}
.main-container .icon{
position:absolute;
top:20px;
right: 20px;
width: 40px;
cursor: pointer;
border-radius: 5%;
}
.reload{
color: white;
background :linear-gradient(45deg, rgb(0, 0, 0),#080505);
}
.wtw{
text-decoration: underline;
color:antiquewhite
}
nav{
flex: 1;
text-align: right;
}
</style>
</head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<body>
<div id = "cont" class="container main-container">
<nav>
<img src = "images/clear.jpg" alt = "theme" class = "icon">
</nav>
<br></br>
<br></br>
<h1 class="wtw">What's The Weather</h1>
<div id = "inputBox" class="input-group mb-3 mt-5">
<input id = "searchBox" type="text" class="form-control form-control-lg" placeholder="Type a city name">
<button type="button" class="btn btn-outline-success" id = "button-addon2"><i class = "fas fa-search fa-lg fa-fw"></i></button>
</div>
<button class="reload" onClick="window.location.href=window.location.href"><i class="fa fa-refresh fa-spin" style="font-size:24px"></i></button>
<div class="card weather-card">
<div class="card-title text-center mt-3">
<h4 id = "city">Delhi</h4>
<h6 id = "date"> Saturday,18th Feb 2023</h6>
</div>
<img id = "image" src="images/clouds.jpg" class="card-img-top" alt="weather image">
<div id = "cbody" class="card-body">
<h6 id = "temp" class = "display-4 font-weight-bold text-center"> 13°C </h6>
<h6 id = "feel" class="display-7 font-weight-bold text-center"> ( Feels like 13°C) </h6>
<h6 id = "weather" class="display-7 text-center" > Haze </h6>
<h5 id = "minmaxTemp" class="text-center"> 25°C(min) / 26°C(max) </h5>
</div>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
More Information
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<ul class = "list-group">
<li id = "humidity" class="list-group-item d-flex justify-content-between align-items-center">
<span>Humidity</span> 53
</li>
<li id = "pressure" class="list-group-item d-flex justify-content-between align-items-center">
<span>Pressure</span> 1018
</li>
<li id = "visibility" class="list-group-item d-flex justify-content-between align-items-center">
<span>Visibility</span> 2100
</li>
<li id = "windspeed" class="list-group-item d-flex justify-content-between align-items-center">
<span>Wind Speed</span> 2000
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
const weatherApi = {
key: "eb7a2d4a5a9b284fe54b7bb547238443",
baseUrl: "https://api.openweathermap.org/data/2.5/weather",
}
const searchBox = document.getElementById("searchBox");
searchBox.addEventListener("keypress", function(event){
if(event.keyCode == 13){
getWeatherReport(searchBox.value);
searchBox.value = "";
}
});
function getWeatherReport(city) {
// https://api.openweathermap.org/data/2.5/weather?q=cityName&appid=eb7a2d4a5a9b284fe54b7bb547238443&unit=metric
fetch(`${weatherApi.baseUrl}?q=${city}&appid=${weatherApi.key}&units=metric`)
.then(function (response) { return response.json() })
.then(function (response) {
showWeatherReport(response);
})
.catch(function (err) {
console.log(err);
})
}
function showWeatherReport(curWeather){
let city = document.getElementById("city");
let date = document.getElementById("date");
let image = document.getElementById("image");
let temp = document.getElementById("temp");
let feel = document.getElementById("feel");
let weather = document.getElementById("weather");
let minmaxTemp = document.getElementById("minmaxTemp");
let humidity = document.getElementById("humidity");
let pressure = document.getElementById("pressure");
let visibility = document.getElementById("visibility");
let windspeed = document.getElementById("windspeed");
console.log(curWeather);
city.innerHTML = curWeather.name;
let todayDate = new Date().toDateString();
date.innerHTML = todayDate;
image.src = manageImage(curWeather.weather[0].main);
temp.innerHTML = Math.round(curWeather.main.temp) + "°C";
feel.innerHTML = `(Feels Like ${Math.round(curWeather.main.feels_like)}°C)`;
weather.innerHTML = curWeather.weather[0].main;
minmaxTemp.innerHTML = `${Math.floor(curWeather.main.temp_min)}°C(min) / ${Math.ceil(curWeather.main.temp_max)}°C(max)`;
humidity.innerHTML = `<span>Humidity</span> ${curWeather.main.humidity}`;
pressure.innerHTML = `<span>Pressure</span> ${curWeather.main.pressure}`;
visibility.innerHTML = `<span>Visibility</span> ${curWeather.visibility}`;
windspeed.innerHTML = `<span>Wind Speed</span> ${curWeather.wind.speed}`;
}
function manageImage(weatherType) {
if (weatherType === 'Clear') {
return "images/clear.jpg";
} else if (weatherType === 'Smoke') {
return "images/smoke.jpg";
} else if (weatherType === 'Haze') {
return "images/haze.jpg";
} else if (weatherType === 'Rain') {
return "images/rain.jpg";
} else if (weatherType === 'Snow') {
return "images/snow.jpg";
} else if (weatherType === 'Thunderstorm') {
return "images/thunderstorm.jpg";
} else if (weatherType === 'Mist') {
return "images/mist.jpg";
} else if (weatherType === 'Clouds') {
return "images/clouds.jpg";
}
else {
return "images/clear.jpg";
}
}
const toggle = document.getElementById('toggleDark');
const body = document.getElementById('cont');
const cbody = document.getElementById('cbody');
const accordionExample = document.getElementById('accordionExample');
toggle.addEventListener('click', function(){
this.classList.toggle('bi-moon');
if(this.classList.toggle('bi-moon-fill')){
body.style.background = 'white';
body.style.color = 'black';
body.style.transition = '2s';
cbody.style.color = 'black';
cbody.style.transition = '2s';
accordionExample.style.color = 'black';
accordionExample.style.transition = '2s';
}
else{
body.style.background = 'black';
body.style.color = 'white';
body.style.transition = '2s';
cbody.style.color = 'white';
cbody.style.transition = '2s';
accordionExample.style.color = 'white';
accordionExample.style.transition = '2s';
}
});
</script>
</body>
</html>