Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Weather Wallpaper</title>
- <style>
- body {
- margin: 0;
- overflow: hidden;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- background-color: #282c34;
- color: white;
- font-family: Arial, sans-serif;
- }
- .weather-container {
- text-align: center;
- }
- </style>
- </head>
- <body>
- <div class="weather-container">
- <h1 id="location">Loading...</h1>
- <h2 id="temperature"></h2>
- <h3 id="description"></h3>
- </div>
- <script>
- const API_KEY = 'YOUR_API_KEY';
- const CITY = 'YOUR_CITY';
- async function fetchWeather() {
- try {
- const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${CITY}&appid=${API_KEY}&units=metric`);
- const data = await response.json();
- updateWeather(data);
- } catch (error) {
- console.error('Error fetching weather data:', error);
- }
- }
- function updateWeather(data) {
- const location = document.getElementById('location');
- const temperature = document.getElementById('temperature');
- const description = document.getElementById('description');
- location.textContent = data.name;
- temperature.textContent = `${data.main.temp}°C`;
- description.textContent = data.weather[0].description;
- }
- fetchWeather();
- setInterval(fetchWeather, 600000); // Update every 10 minutes
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment