Skip to content

WeatherApp-chiragmetaliya #1151

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

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
Binary file added WeatherApp/chiragmetaliya/images/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WeatherApp/chiragmetaliya/images/cloudy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WeatherApp/chiragmetaliya/images/rainy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WeatherApp/chiragmetaliya/images/sunny.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions WeatherApp/chiragmetaliya/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather App</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.10/css/weather-icons.min.css">
</head>
<body>
<div class="weather-app">
<h1>Weather App</h1>
<input type="text" id="city-input" placeholder="Enter city name">
<button id="search-btn">Search</button>
<div id="weather-info">
<!-- Weather information will be displayed here -->
</div>
</div>
<script src="script.js"></script>
</body>
</html>
53 changes: 53 additions & 0 deletions WeatherApp/chiragmetaliya/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const apiKey = '11b99e1fc528f63c99423edeae4f422c';

document.getElementById('search-btn').addEventListener('click', function() {
const city = document.getElementById('city-input').value;
const apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`;

fetch(apiUrl)
.then(response => response.json())
.then(data => {
displayWeather(data);
})
.catch(error => {
console.error('Error fetching the weather data:', error);
});
});

function displayWeather(data) {
const weatherInfo = document.getElementById('weather-info');
const body = document.body;

if (data.cod === 200) {
const { temp } = data.main;
const { description, icon } = data.weather[0];
const { humidity } = data.main;
const { speed } = data.wind;

let background = 'background.jpg'; // Default background
if (description.includes('rain')) {
background = 'rainy.jpg';
} else if (description.includes('cloud')) {
background = 'cloudy.jpg';
} else if (description.includes('sun')) {
background = 'sunny.jpg';
}

body.style.backgroundImage = `url('images/${background}')`;

weatherInfo.innerHTML = `
<div class="weather-item"><strong>Temperature:</strong> ${temp} °C</div>
<div class="weather-item">
<strong>Condition:</strong> ${description}
<img src="http://openweathermap.org/img/wn/${icon}@2x.png" alt="Weather Icon">
</div>
<div class="weather-item"><strong>Humidity:</strong> ${humidity}%</div>
<div class="weather-item"><strong>Wind Speed:</strong> ${speed} m/s</div>
`;

weatherInfo.classList.add('show');
} else {
weatherInfo.innerHTML = `<div class="weather-item">City not found</div>`;
weatherInfo.classList.remove('show');
}
}
93 changes: 93 additions & 0 deletions WeatherApp/chiragmetaliya/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* General Styles */
body {
font-family: 'Roboto', sans-serif;
background: url('images/background.jpg') no-repeat center center fixed;
background-size: cover;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
transition: background 0.5s ease-in-out;
}

.weather-app {
text-align: center;
background: rgba(255, 255, 255, 0.9);
padding: 30px 40px;
border-radius: 10px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
width: 300px;
max-width: 90%;
}

h1 {
color: #333;
margin-bottom: 20px;
font-size: 24px;
}

#city-input {
padding: 10px;
width: 100%;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 10px;
font-size: 16px;
}

#search-btn {
padding: 10px 25px;
background: #007BFF;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background 0.3s;
width: 100%;
}

#search-btn:hover {
background: #0056b3;
}

#weather-info {
margin-top: 25px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}

#weather-info.show {
opacity: 1;
}

.weather-item {
margin: 10px 0;
font-size: 18px;
color: #333;
}

.weather-item strong {
color: #555;
}

.weather-item img {
vertical-align: middle;
margin-left: 10px;
}

@media (max-width: 600px) {
.weather-app {
padding: 20px;
width: 90%;
}

h1 {
font-size: 20px;
}

.weather-item {
font-size: 16px;
}
}
Loading