Match satellite's tles via NORAD catalogue id

This commit is contained in:
phl0
2025-03-12 10:44:30 +01:00
parent a1760c44b9
commit 57dfe8cdf7
2 changed files with 19 additions and 7 deletions

View File

@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
*/
$config['migration_version'] = 237;
$config['migration_version'] = 238;
/*
|--------------------------------------------------------------------------

View File

@@ -316,10 +316,11 @@ class Update_model extends CI_Model {
$this->load->model('cron_model');
$this->cron_model->set_last_run($this->router->class . '_' . $this->router->method);
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$this->update_norad_ids();
$url = 'https://www.amsat.org/tle/dailytle.txt';
$curl = curl_init($url);
@@ -345,18 +346,18 @@ class Update_model extends CI_Model {
// Check if there are at least three lines remaining
if (isset($lines[$i], $lines[$i + 1], $lines[$i + 2])) {
// Get the three lines
$satname = $lines[$i];
$satname = substr($lines[$i+1], 2, 5);
$tleline1 = $lines[$i + 1];
$tleline2 = $lines[$i + 2];
$sql = "
INSERT INTO tle (satelliteid, tle)
SELECT id, ?
FROM satellite
WHERE name = ? OR displayname = ?
WHERE norad_id = ?
ON DUPLICATE KEY UPDATE
tle = VALUES(tle), updated = now()
";
$this->db->query($sql, array($tleline1 . "\n" . $tleline2, $satname, $satname));
$this->db->query($sql, array($tleline1 . "\n" . $tleline2, $satname));
}
}
}
@@ -472,4 +473,15 @@ class Update_model extends CI_Model {
}
}
function update_norad_ids() {
$csvfile = 'https://www.df2et.de/cqrlog/lotw_norad.csv';
$csvhandle = fopen($csvfile, "r");
while (false !== ($data = fgetcsv($csvhandle, 1000, ","))) {
$this->db->set('norad_id', $data[1]);
$this->db->where('name', $data[0]);
$this->db->update('satellite');
}
return;
}
}