weather.
html:
<!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="[Link]">
<title>Major Project</title>
</head>
<body onload="DefaultScreen()">
<center>
<h1 id="Para1">7 Days Weather Forecast</h1>
<p id="inputContainer">City: <input type="text" id="cityInput"></p>
<button type="button" onclick="GetInfo()">Click Me</button>
<h2 id="cityName">---Delhi---</h2>
</center>
<div class="time" id="time">
12:30 <span id="am-pm">PM</span>
</div>
<div class="date" id="date">
Monday, 25 May
</div>
<div class="current-info">
<div class="current-info">humidity</div>
<div class="weather-item"></div>
</div>
<!-- <div id = "weatherContainer"> -->
<div class="future-forecast">
<div id="iconsContainer">
<div class="today">
<div class = "icons">
<p class="weather" id="day1"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img1"></div>
<p class="minValues" id="day1Min">Loading...</p>
<p class="maxValues" id="day1Max">Loading...</p>
</div>
</div>
<div class = "icons">
<p class="weather" id="day2"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img2"></div>
<p class="minValues" id="day2Min">Loading...</p>
<p class="maxValues" id="day2Max">Loading...</p>
</div>
<div class = "icons">
<p class="weather" id="day3"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img3"></div>
<p class="minValues" id="day3Min">Loading...</p>
<p class="maxValues" id="day3Max">Loading...</p>
</div>
<div class = "icons">
<p class="weather" id="day4"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img4"></div>
<p class="minValues" id="day4Min">Loading...</p>
<p class="maxValues" id="day4Max">Loading...</p>
</div>
<div class = "icons">
<p class="weather" id="day5"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img5"></div>
<p class="minValues" id="day5Min">Loading...</p>
<p class="maxValues" id="day5Max">Loading...</p>
</div>
<div class = "icons">
<p class="weather" id="day6"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img6"></div>
<p class="minValues" id="day6Min">Loading...</p>
<p class="maxValues" id="day6Max">Loading...</p>
</div>
<div class = "icons">
<p class="weather" id="day7"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img7"></div>
<p class="minValues" id="day7Min">Loading...</p>
<p class="maxValues" id="day7Max">Loading...</p>
</div>
<div class = "icons">
<p class="weather" id="day8"></p>
<div class="image"><img src="[Link]" class="imgClass"
id="img8"></div>
<p class="minValues" id="day8Min">Loading...</p>
<p class="maxValues" id="day8Max">Loading...</p>
</div>
</div>
</div>
<script src="[Link]"></script>
<center><footer><i>Thank you!</i></footer></center>
</body>
</html>
[Link]:
*{/*overall body*/
color: rgb(9, 15, 17);
/*background: rgb(7, 243, 113);*/
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
box-sizing: border-box;
margin:0;
padding:0;
}
#cityInput, #cityName, #inputContainer{
margin: 3px;
padding:5px;
text-align:center;
font-size:18px;
font-weight:bold;
z-index: 5;
}
#inputContainer{/*city:background-color:*/
background-color:burlywood;
}
button{/*button*/
margin: 3px;
padding:5px;
background-color: antiquewhite;
text-align:center;
font-size:20px;
font-weight:bold;
z-index:5;
}
#weatherContainer{/*first line*/
position: absolute;
top: 70%;
left: 51.5%;
margin-right: -50%;
transform: translate(-50%, -50%);
height: 300px;
width: 1300px;
border: 5px solid rgba(97, 95, 95, 0.829);
border-radius: 10px;
}
#iconsContainer{/*second line*/
display: flex;
position: absolute;
background-color: rgba(0,0,0,0.2);;
top: 80%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
height: 240px;
width: 1400px;
border: 5px solid rgb(31, 82, 82);
border-radius: 25px;
justify-content: start;
align-items: none;
/* overflow-y: hidden; */
}
.icons{/*boxes*/
display: inline-bock;
float: left;
height: 200px;
width: 130px;
margin: 20px;
border: 5px solid rgb(48, 47, 47);
border-radius: 10px;
}
.image{/*min-max text alignment*/
height: 110px;
width: 100%;
}
.imgClass{/*icons*/
height: 140px;
width: 100%;
}
.weather{/*day name bgcolor*/
margin: 5px;
background-color: rgb(31, 168, 168);
border-radius: 15px;
text-align: center;
font-weight: bold;
}
.minValues{/*min alignment up&down*/
color: white;
text-align: center;
display: inline-block;
border-radius: 5px;
height: 15px;
width: 45px;
margin: 0;
margin-bottom: 5px;
margin-left: 5px;
}
.maxValues{/*max alignment up&down*/
color: white;
text-align: center;
display: inline-block;
border-radius: 5px;
height: 15px;
width: 45px;
margin: 0;
margin-bottom: 5px;
margin-left: 5px;
}
/* */
@import url('[Link]
family=Poppins:wght@100;200;400;700&display=swap');
body{
background:url('[Link]
37aace184f49?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-
1.2.1');
background-repeat:round;
background-size:cover;
/* overflow:scroll; */
height: 100vh;
font-family: 'Poppins', sans-serif;
}
.container{/*moving time from left to towards right*/
top: 20%;
padding: 10px 70px;
color:#fff;
}
.current-info{/*imp/current-info->[Link]-container,[Link]-container*/
display: flex;
padding: 20px 70px;
justify-content: space-between;
flex-wrap: wrap;
}
.date-container{/*date time font size*/
font-weight: 600;
}
.date-container .time{/*time:12:30*/
color: white;
font-size: 170px;
}
.date-container #am-pm{/*am/pm*/
color: white;
font-size: 30px;
margin-left: 20px;
}
.date-container .date{/*date*/
color: white;
font-size: 30px;
}
.place-container{/**/
color: rgb(199, 25, 25);
text-align: end;
}
/*place-container*/.time-zone{/*Asia/Kolkatta*/
color: white;
text-align: right;
font-size: 30px;
font-weight: 100;
text-align: right;
}
/*place-container*/ .country{/*latitudes and longitudes*/
color: white;
font-size: 12px;
font-weight: 700;
text-align: end;
}
.time {/*time*/
color:white;
font-weight: bold;
font-size: 20px;
}
#am-pm{/*am/pm*/
color:white;
font-weight: 700;
font-size: 20px;
}
.date{/*date*/
color:white;
}
.current-info .others{/*imp*/
display: flex;
flex-direction: column;
background: rgba(24,24,27, 0.6);
padding:0px 70px;
border-radius: 10px;
margin: 10px 0;
border: 1px solid #eee;
text-align:right;
}
.current-info .others .weather-item{/**/
display: flex;
justify-content: space-between;
}
.future-forecast{/*black strip in weatherApp*/
/* background: rgba(17, 17, 22, 0.8); */
padding: 25px;
position: fixed;
bottom: 0;
display: flex;
color:white;
width: 100%;
height: 100%;
align-items: center;
justify-content: space-between;
overflow-y: hidden;
}
.future-forecast .today{/*today info &bg*/
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #eee;
border-radius: 10px;
padding:25px;
padding-right: 40px;
border-radius: 10px;
background: rgba(0,0,0,0.2)
}
/* .future-forecast .today .day{
padding: 5px 15px;
background: #3c3c44;
border-radius: 50px;
text-align: center;
}
.future-forecast .today .temp{
font-size: 18px;
padding-top: 15px;
}*/
.future-forecast .weather-forecast{
display: flex;
}
.weather-forecast .weather-forecast-item{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0 10px;
border: 1px solid #eee;
padding: 15px;
border-radius: 10px;
background: rgba(0,0,0,0.2)
}
.weather-forecast .weather-forecast-item .day{
padding: 5px 15px;
background: #3C3C44;
border-radius: 50px;
text-align: center;
}
.weather-forecast .weather-forecast-item .temp{
font-weight: 100;
font-size: 12px;
}
.weather-item{
padding: 75px;
}
@media only screen and (max-width:730px){
.container{
padding: 20px;
}
.future-forecast{
justify-content: start;
align-items: none;
overflow-y: scroll;
}
.future-forecast .today .temp{
font-size: 16px;
}
.date-container .time{
font-size: 50px;
}
.date-container #am-pm{
font-size: 20px;
}
.date-container .date{
font-size: 20px;
}
/* .place-container{
text-align: end;
margin-top: 15px;
}
.place-container .time-zone{
font-size: 20px;
}*/
.current-info .others{
padding: 12px;
}
.current-info .others .weather-item{
font-size: 14px;
}
}
@media only screen and (max-width: 1400px){
.future-forecast{
justify-content: start;
align-items: none;
overflow-x: scroll;
}
}
[Link]:
function GetInfo()
{
var newName = [Link]("cityInput");
var cityName = [Link]("cityName");
[Link] = "--"+[Link]+"--";
fetch('[Link]
q='+[Link]+'&appid=f02d68936905fe8381426343096ae320')
.then(response => [Link]())
.then(data => {
//Getting the min and max values for each day
for(i = 0; i<8; i++)
{
[Link]("day" + (i+1) + "Min").innerHTML = "Min: " +
Number([Link][i].main.temp_min - 273.15).toFixed(1)+ "°";
//Number(1.3450001).toFixed(2); // 1.35
}
for(i = 0; i<8; i++)
{
[Link]("day" + (i+1) + "Max").innerHTML = "Max: " +
Number([Link][i].main.temp_max - 273.15).toFixed(2) + "°";
}
//------------------------------------------------------------
//Getting Weather Icons
for(i = 0; i<8; i++)
{
[Link]("img" + (i+1)).src =
"[Link]
[Link][i].weather[0].icon
+".png";
}
//------------------------------------------------------------
[Link](data)
})
.catch(err => alert("Something Went Wrong: Try Checking Your Internet
Coneciton"))
}
/////
const timeEl = [Link]('time');
const dateEl = [Link]('date');
const currentWeatherItemsEl = [Link]('current-weather-
items');
const timezone = [Link]('time-zone');
const countryEl = [Link]('country');
const weatherForecastEl = [Link]('weather-forecast');
const currentTempEl = [Link]('current-temp');
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday']
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'];
const API_KEY ='f02d68936905fe8381426343096ae320';
setInterval(() => {
const time = new Date();
const month = [Link]();
const date = [Link]();
const day = [Link]();
const hour = [Link]();
const hoursIn12HrFormat = hour >= 13 ? hour %12: hour
const minutes = [Link]();
const ampm = hour >=12 ? 'PM' : 'AM'
[Link] = (hoursIn12HrFormat < 10? '0'+hoursIn12HrFormat :
hoursIn12HrFormat) + ':' + (minutes < 10? '0'+minutes: minutes)+ ' ' + `<span
id="am-pm">${ampm}</span>`
[Link] = days[day] + ', ' + date+ ' ' + months[month]
}, 1000);
getWeatherData()
function getWeatherData()
{
[Link]((success) => {
let {latitude, longitude } = [Link];
fetch(`[Link]
{latitude}&lon=${longitude}&exclude=hourly,minutely&units=metric&appid=$
{API_KEY}`).then(res => [Link]()).then(data => {
[Link](data)
showWeatherData(data);
})
})
}
function showWeatherData(data)
{
let {humidity, pressure, sunrise, sunset, wind_speed} = [Link];
[Link] = [Link];
[Link] = [Link] + 'N ' + [Link]+'E'
[Link] =
`<div class="weather-item">
<div>Humidity</div>
<div>${humidity}%</div>
</div>
<div class="weather-item">
<div>Pressure</div>
<div>${pressure}</div>
</div>
<div class="weather-item">
<div>Wind Speed</div>
<div>${wind_speed}</div>
</div>
<div class="weather-item">
<div>Sunrise</div>
<div>${[Link](sunrise * 1000).format('HH:mm a')}</div>
</div>
<div class="weather-item">
<div>Sunset</div>
<div>${[Link](sunset*1000).format('HH:mm a')}</div>
</div>
`;
}
/////
function DefaultScreen()
{
[Link]("cityInput").defaultValue = "Delhi";
GetInfo();
}
//Getting and displaying the text for the upcoming five days of the week
var d = new Date();
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday",];
//Function to get the correct integer for the index of the days array
function CheckDay(day)
{
if(day + [Link]() > 6)
{
return day + [Link]() - 7;
}
else
{
return day + [Link]();
}
}
for(i = 0; i<8; i++)
{
[Link]("day" + (i+1)).innerHTML =
weekday[CheckDay(i)];
}
//------------------------------------------------------------
/*[Link]("day1Min").innerHTML =
[Link]([Link][0].main.temp_min - 273.15, -2);
[Link]("day2Min").innerHTML =
[Link]([Link][1].main.temp_min - 273.15, -2);
[Link]("day3Min").innerHTML =
[Link]([Link][2].main.temp_min - 273.15, -2);
[Link]("day4Min").innerHTML =
[Link]([Link][3].main.temp_min - 273.15, -2);
[Link]("day5Min").innerHTML =
[Link]([Link][4].main.temp_min - 273.15, -2);
[Link]("day6Min").innerHTML =
[Link]([Link][5].main.temp_min - 273.15, -2);
[Link]("day7Min").innerHTML =
[Link]([Link][6].main.temp_min - 273.15, -2);
[Link]("day8Min").innerHTML =
[Link]([Link][7].main.temp_min - 273.15, -2);*/
/*[Link]("day1Max").innerHTML =
[Link]([Link][0].main.temp_max - 273.15, -2);
[Link]("day2Max").innerHTML =
[Link]([Link][0].main.temp_max - 273.15, -2);
[Link]("day3Max").innerHTML =
[Link]([Link][0].main.temp_max - 273.15, -2);
[Link]("day4Max").innerHTML =
[Link]([Link][0].main.temp_max - 273.15, -2);
[Link]("day5Max").innerHTML =
[Link]([Link][0].main.temp_max - 273.15, -2);*/
/*[Link]("img1").src = "[Link]
[Link][0].weather[0].icon
+".png";
[Link]("img2").src = "[Link]
[Link][1].weather[0].icon
+".png";
[Link]("img3").src = "[Link]
[Link][2].weather[0].icon
+".png";
[Link]("img4").src = "[Link]
[Link][3].weather[0].icon
+".png";
[Link]("img5").src = "[Link]
[Link][4].weather[0].icon
+".png";*/
/*
[Link]("day1").innerHTML = weekday[CheckDay(0)];
[Link]("day2").innerHTML = weekday[CheckDay(1)];
[Link]("day3").innerHTML = weekday[CheckDay(2)];
[Link]("day4").innerHTML = weekday[CheckDay(3)];
[Link]("day5").innerHTML = weekday[CheckDay(4)];*/
/*weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";*/