PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); // Quelldatei bestimmen $sourceFile = $argv[1] ?? null; $tempFile = null; if ($sourceFile !== null) { if (!file_exists($sourceFile)) { exit("Datei nicht gefunden: {$sourceFile}\n"); } $content = file_get_contents($sourceFile); } else { echo "Lade qs.mag von Mirror...\n"; $url = 'https://raw.githubusercontent.com/barolfe/satellite-tracker/master/qs.mag'; $content = @file_get_contents($url); if ($content === false) { exit("Download fehlgeschlagen. Bitte qs.mag manuell herunterladen und als Argument uebergeben.\n"); } echo "Download OK (" . strlen($content) . " Bytes).\n"; } $lines = explode("\n", str_replace("\r\n", "\n", $content)); $stmt = $pdo->prepare(" UPDATE `sat_satellites` SET `std_mag` = :std_mag WHERE `norad_cat_id` = :norad "); $updated = 0; $skipped = 0; $noMag = 0; foreach ($lines as $line) { // Mindestlaenge und Header-Zeile ueberspringen if (strlen($line) < 20) { continue; } $norad = (int)substr($line, 0, 5); if ($norad === 0) { continue; // Header oder Leerzeile } // Magnitude steht nach dem Namensfeld (ab ~Position 25), // als erster Float-Wert (kann negativ sein, z.B. -1.5 fuer ISS) if (!preg_match('/^.{25,}\s+([-\d]+\.?\d*)\s/', $line, $m)) { $noMag++; continue; } $stdMag = (float)$m[1]; $stmt->execute([':std_mag' => $stdMag, ':norad' => $norad]); if ($stmt->rowCount() > 0) { $updated++; } else { $skipped++; // Satellit nicht in DB } } echo "Fertig.\n"; echo " Aktualisiert: {$updated}\n"; echo " Nicht in DB: {$skipped}\n"; echo " Ohne Mag: {$noMag}\n";