-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
197 lines (167 loc) · 7.21 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
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- Bootstrap CSS v5.2.1 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
</head>
<body>
<header>
<!-- place navbar here -->
</header>
<main>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Weather App</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About this App</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Usage Guide
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1">How to Use?</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" id="city" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit" id="submit">Search</button>
</form>
</div>
</div>
</nav>
<h1 class="my-4 text-center">Weather for <span id="cityName"></span></h1>
<div class="row row-cols-1 row-cols-md-3 mb-3 text-center">
<div class="col">
<div class="card mb-4 rounded-3 px-3 py-3 shadow-sm">
<div class="card-header py-3 text-bg-primary border-primary">
<h4 class="my-0 fw-normal">Temperatures</h4>
</div>
<div class="card-body">
<h1 class="card-title pricing-card-title"><span id="temp2"></span><small
class="text-body-primary fw-light">°C</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>Temperature is <span id="temp"></span></li>
<li>Maximum Tempurature is <span id="max_temp"></span></li>
<li>Minimum Temperature is <span id="min_temp"></span></li>
</ul>
</div>
</div>
</div>
<div class="col">
<div class="card mb-4 rounded-3 shadow-sm px-3 py-3">
<div class="card-header py-3 text-bg-primary border-primary">
<h4 class="my-0 fw-normal">Humidity Info</h4>
</div>
<div class="card-body">
<h1 class="card-title pricing-card-title"><span id="humidity2"></span><small
class="text-body-secondary fw-light">%</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>Cloud pct is <span id="cloud_pct"></span></li>
<li>Feels like <span id="feels_like"></span></li>
<li>Humidity <span id="humidity"></span></li>
</ul>
</div>
</div>
</div>
<div class="col">
<div class="card mb-4 rounded-3 shadow-sm px-3 py-3">
<div class="card-header py-3 text-bg-primary border-primary">
<h4 class="my-0 fw-normal">Wind Info</h4>
</div>
<div class="card-body">
<h1 class="card-title pricing-card-title"><span id="wind_speed2"></span><small
class="text-body-secondary fw-light">km/hr</small></h1>
<ul class="list-unstyled mt-3 mb-4">
<li>Wind speed is <span id="wind_speed"></span></li>
<li>Sunrise time is <span id="sunrise"></span></li>
<li>Sunset time is <span id="sunset"></span></li>
</ul>
</div>
</div>
</div>
</div>
<script type="module">
const url = 'https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=' + city;
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'cc2568f4e6msh2026822e4e79114p1078f6jsn656f094a3edd',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
}
};
const getWeather = async (city) => {
cityName.innerHTML = city
const url = 'https://weather-by-api-ninjas.p.rapidapi.com/v1/weather?city=' + city; // Replace with your actual API URL
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-RapidAPI-Key': 'cc2568f4e6msh2026822e4e79114p1078f6jsn656f094a3edd',
'X-RapidAPI-Host': 'weather-by-api-ninjas.p.rapidapi.com'
// Add any other headers as needed
},
// Add any other options like body, credentials, etc.
};
try {
const response = await fetch(url, options);
const result = await response.json(); // Assuming the response is JSON
console.log(result);
// Assuming response is an object with properties like cloud_pct, temp, feels_like, humidity, etc.
// Update HTML elements with the properties
document.getElementById('cloud_pct').innerHTML = result.cloud_pct;
document.getElementById('temp').innerHTML = result.temp;
document.getElementById('temp2').innerHTML = result.temp;
document.getElementById('feels_like').innerHTML = result.feels_like;
document.getElementById('humidity').innerHTML = result.humidity;
document.getElementById('humidity2').innerHTML = result.humidity;
document.getElementById('min_temp').innerHTML = result.min_temp;
document.getElementById('max_temp').innerHTML = result.max_temp;
document.getElementById('wind_speed').innerHTML = result.wind_speed;
document.getElementById('wind_speed2').innerHTML = result.wind_speed;
document.getElementById('sunrise').innerHTML = result.sunrise;
document.getElementById('sunset').innerHTML = result.sunset;
} catch (error) {
console.error(error);
}
}
// Example usage:
submit.addEventListener("click", (e)=>{
e.preventDefault()
getWeather(city.value);
})
</script>
</main>
<!-- Bootstrap JavaScript Libraries -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-BBtl+eGJRgqQAUMxJ7pMwbEyER4l1g+O15P+16Ep7Q9Q+zqX6gSbd85u4mG4QzX+" crossorigin="anonymous">
</script>
</body>
</html>