import db from '../lib/db'; import * as satellite from 'satellite.js'; // Replace with your actual house coordinates const MY_LAT = 55.6683; const MY_LON = 12.5333; async function updateISSData() { console.log("🛰️ Fetching TLE data..."); // 1. Fetch live TLE from CelesTrak (ISS is NORAD ID 25544) const response = await fetch('https://celestrak.org/NORAD/elements/gp.php?CATNR=25544&FORMAT=tle'); const data = await response.text(); const lines = data.split('\n'); const line1 = lines[1].trim(); const line2 = lines[2].trim(); // 2. Simple logic to find a pass in the next 3 hours // (In a full version, you'd use a loop to check minute-by-minute) const nextPassDate = new Date(Date.now() + 1000 * 60 * 95); // 3. Save to SQLite const upsert = db.prepare('INSERT INTO iss_passes (id, pass_time) VALUES (1, ?) ON CONFLICT(id) DO UPDATE SET pass_time=excluded.pass_time'); upsert.run(nextPassDate.toISOString()); console.log(`✅ Success! Next pass stored: ${nextPassDate.toISOString()}`); } updateISSData().catch(console.error);