Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather Website added in Program's contributed by Contributors #7792

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Program's_Contributed_By_Contributors/Weather_website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Website</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>

<body>
<div class="container">
<h2>Check the Weather</h2>

<div class="search">
<input type="text" placeholder="enter city name" class="cityName">
<button><i class="fa-solid fa-magnifying-glass"></i></button>
</div>

<div class="weather">
<img src="images/rain.png" class="weather-icon">
<h1 class="temp">22 °C</h1>
<h2 class="city">Mumbai</h2>

<div class="details">
<div class="col">
<img src="images/humidity.png" class="humidity-icon">
<div>
<p class="humidity">50%</p>
<p>Humidity</p><br>

</div>
</div>

<div class="col">
<img src="images/wind.png" class="wind-icon">
<div>
<p class="wind">15 km/h</p>
<p>Wind Speed</p><br>
</div>
</div>
</div>
</div>

</div>

<script src="script.js"></script>
</body>

</html>
61 changes: 61 additions & 0 deletions Program's_Contributed_By_Contributors/Weather_website/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const apiKey = "c21ef0ab41cdd3b3089d1ce8db8e3c21";
const apiURL = `https://api.openweathermap.org/data/2.5/weather?q=mumbai`;

const searchBox = document.querySelector(".search input");
let searchBtn = document.querySelector(".search button");
const baseURL = "https://api.openweathermap.org/data/2.5/weather?q=";

const weatherIcon = document.querySelector(".weather-icon");


async function defaultWeather() {
const response = await fetch(apiURL + `&appid=${apiKey}&units=metric`);
let data = await response.json();
document.querySelector(".city").innerHTML = data.name;
document.querySelector(".temp").innerHTML = Math.round(data.main.temp) + "°C"
document.querySelector(".wind").innerHTML = data.wind.speed + "km/h"
document.querySelector(".humidity").innerHTML = data.main.humidity + "%";
}

defaultWeather();


async function checkWeather() {

let cityName = searchBox.value;
const reqURL = `${baseURL}${cityName}&appid=${apiKey}&units=metric`;
const response = await fetch(reqURL);
let data = await response.json();
document.querySelector(".city").innerHTML = data.name;
document.querySelector(".temp").innerHTML = Math.round(data.main.temp) + "°C"
document.querySelector(".wind").innerHTML = data.wind.speed + "km/h"
document.querySelector(".humidity").innerHTML = data.main.humidity + "%";

if (data.weather[0].main == "Clouds") {
weatherIcon.src = "images/clouds.png";
}

else if (data.weather[0].main == "Clear") {
weatherIcon.src = "images/clear.png";
}

else if (data.weather[0].main == "Drizzle") {
weatherIcon.src = "images/drizzle.png";
}

else if (data.weather[0].main == "Mist") {
weatherIcon.src = "images/mist.png";
}

else if (data.weather[0].main == "Rain") {
weatherIcon.src = "images/rain.png";
}

else if (data.weather[0].main == "Snow") {
weatherIcon.src = "images/snow.png";
}
}

searchBtn.addEventListener("click", () => {
checkWeather()
})
93 changes: 93 additions & 0 deletions Program's_Contributed_By_Contributors/Weather_website/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
* {
margin: 0;
padding: 0;
font-family: 'Times New Roman', Times, serif;
}

body {

background-color: #03045E;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}

.container {
width: 90%;
/* adjuts the height accordingly, very very important */
max-width: 450px;
background-color: #00B4D8;
border-radius: 1rem;
padding: 1.5rem;
text-align: center;
}

h2 {
margin: 1rem;
text-align: center;
color: white;
}

.search {
display: flex;
justify-content: space-between;
outline: none;
border: none;
border-radius: 1rem;
padding: 1rem;
background-color: #CAF0F8;
}

.search input {
width: 50%;
margin-right: 1rem;
outline: none;
border: none;
background-color: #CAF0F8;
}

.search button,
i {
outline: none;
border: none;
background-color: #CAF0F8;
height: max-content;
}

.weather h1 {
font-size: 80px;
font-weight: 500;
margin-top: -10px;
}

.weather h2 {
margin-top: 0px;
font-size: 45px;
font-weight: 400;
}

.details {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
margin-top: 1.5rem;
}

.col {
display: flex;
align-items: center;
text-align: center;
}

.col img {
width: 75px;
margin-right: 1rem;
}

.humidity,
.wind {
font-size: 28px;
margin-bottom: 0.5rem;
}