Spaces:
Sleeping
Sleeping
Upload index.html
Browse files133 unmodified lines1341351361371381391401411422 unmodified lines14514614714814915015132 unmodified lines184185186187188189190133 unmodified lines</body><script>let currentLat = 18.34;let currentLon = 74.03;let currentCity = "Saswad, Maharashtra";async function fetchAgriWeather(lat, lon, cityName) {try {2 unmodified linesconst container = document.getElementById('forecast-container');container.innerHTML = '<p>Loading satellite data...</p>';// Fetch Weatherconst response = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&daily=temperature_2m_max,temperature_2m_min,precipitation_sum&timezone=auto`);const data = await response.json();32 unmodified linesdocument.getElementById('forecast-container').innerHTML = "<p>Unable to load weather data.</p>";}}// Search Logicasync function searchLocation() {const query = document.getElementById('city-search').value;133 unmodified lines1341351361371381391401411422 unmodified lines14514614714814915032 unmodified lines183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236133 unmodified lines</body><script>let currentLat = 18.1654;let currentLon = 73.9745;let currentCity = "Dhangawadi, Bhor";async function fetchAgriWeather(lat, lon, cityName) {try {2 unmodified linesconst container = document.getElementById('forecast-container');container.innerHTML = '<p>Loading satellite data...</p>';const response = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&daily=temperature_2m_max,temperature_2m_min,precipitation_sum&timezone=auto`);const data = await response.json();32 unmodified linesdocument.getElementById('forecast-container').innerHTML = "<p>Unable to load weather data.</p>";}}async function fetchAgriWeather(lat, lon, cityName) {const container = document.getElementById('forecast-container');const alertBox = document.querySelector('#agri-alert span');const apiKey = "1064acda807142a4bd551225260704";try {document.getElementById('current-loc').innerText = `📍 ${cityName}`;alertBox.innerHTML = "Fetching certified weather data...";container.innerHTML = '<p>Loading...</p>';const url = `https://api.weatherapi.com/v1/forecast.json?key=${apiKey}&q=${lat},${lon}&days=7&aqi=no&alerts=no`;const response = await fetch(url);if (!response.ok) throw new Error("API Key Error or Limit Reached");const data = await response.json();container.innerHTML = '';const forecastDays = data.forecast.forecastday;forecastDays.forEach(day => {const dateObj = new Date(day.date);const dayName = dateObj.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric' });const maxTemp = Math.round(day.day.maxtemp_c);const rain = day.day.totalprecip_mm;const iconUrl = day.day.condition.icon;container.innerHTML += `<div class="forecast-card"><div class="date">${dayName}</div><img src="${iconUrl}" alt="weather" style="width: 40px;"><div class="temp">${maxTemp}°C</div><div class="rain">💧 ${rain} mm</div></div>`;});const tomorrow = forecastDays[1].day;if (tomorrow.totalprecip_mm > 2) {alertBox.innerHTML = "<strong>Alert:</strong> Heavy rain expected tomorrow. Delay pesticide spraying and ensure field drainage.";} else if (tomorrow.maxtemp_c > 35) {alertBox.innerHTML = "<strong>Alert:</strong> High heat warning tomorrow. Irrigate crops early in the morning.";} else {alertBox.innerHTML = "<strong>Advice:</strong> Weather is stable. Good conditions for harvesting and routine field work.";}} catch (error) {console.error("API Key Method Failed:", error);}}// Search Logicasync function searchLocation() {const query = document.getElementById('city-search').value;
templates/index.html+50-4