Basic implementation to update SAT data from LoTW/tqsl

This commit is contained in:
phl0
2024-12-09 21:34:46 +01:00
parent 00be2bc003
commit e70050cbed
3 changed files with 86 additions and 14 deletions

View File

@@ -389,11 +389,17 @@ class Update extends CI_Controller {
}
public function update_tle() {
$this->load->model('Update_model');
public function update_tle() {
$this->load->model('Update_model');
$result = $this->Update_model->tle();
echo $result;
}
}
public function update_lotw_sats() {
$this->load->model('Update_model');
$result = $this->Update_model->lotw_sats();
echo $result;
}
function version_check() {
// set the last run in cron table for the correct cron id

View File

@@ -359,13 +359,79 @@ class Update_model extends CI_Model {
curl_close($curl);
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds <br />";
echo "Records inserted: " . $count . " <br/>";
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds <br />";
echo "Records inserted: " . $count . " <br/>";
}
function lotw_sats() {
$url = 'https://lotw.arrl.org/lotw/config.tq6';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER,true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo __('cURL error:').' '.curl_error($curl).' ('.curl_errno($curl).')';
return;
}
curl_close($curl);
$xml = simplexml_load_string(gzdecode($response));
$existingSats = array();
$this->db->select('name, lotw');
$query = $this->db->get('satellite');
foreach($query->result() as $row) {
$existingSats[$row->name] = $row->lotw;
}
//$existingSats = $query->result_array();
print '<table>';
print '<tr><th>'.__('Name').'</th><th>'.__('Display Name').'</th><th>'.__('Start Date').'</th><th>'.__('End Date').'</th><th>'.__('Status').'</th></tr>';
foreach ($xml->tqslconfig->satellites->satellite as $sat) {
$name = $sat->attributes()->{'name'};
$startDate = $sat->attributes()->{'startDate'};
$endDate = $sat->attributes()->{'endDate'};
$displayname = $sat;
$status = '';
if (array_key_exists("$name", $existingSats)) {
if ($existingSats["$name"] == 'N') {
$this->db->set('lotw', 'Y');
$this->db->where('name', $name);
$this->db->update('satellite');
if ($this->db->affected_rows() > 0) {
$status = __('SAT already existing. LoTW status updated.');
} else {
$status = __('SAT already existing. Updating LoTW status failed.');
}
} else {
$status = __('SAT already existing. Ignored.');
}
} else {
$data = array(
'name' => $name,
'displayname' => $displayname,
'lotw' => 'Y',
);
if ($this->db->insert('satellite', $data)) {
$status = __('New SAT. Inserted.');
} else {
$status = __('New SAT. Insert failed.');
}
}
print('<tr><td>'.$name.'</td><td>'.$displayname.'</td><td>'.$startDate.'</td><td>'.$endDate.'</td><td>'.$status.'</td></tr>');
}
print '</table>';
return;
}
}

View File

@@ -34,7 +34,7 @@
<td style="text-align: center; vertical-align: middle;" class="satellite_<?php echo $sat->id ?>"><?php echo htmlentities($sat->satname) ?></td>
<td style="text-align: center; vertical-align: middle;"><?php echo $sat->displayname ? htmlentities($sat->displayname) : '' ?></td>
<?php echo '<td style="text-align: center; vertical-align: middle;"><span class="badge ';
switch (strtoupper($sat->orbit)) {
switch (strtoupper($sat->orbit ?? '')) {
case 'LEO':
echo 'bg-primary';
break;
@@ -42,13 +42,13 @@
echo 'bg-info';
break;
case 'GEO':
echo 'bg-warning';
echo 'bg-secondary';
break;
default:
echo 'bg-light';
echo 'bg-warning';
break;
}
echo '">'.$sat->orbit.'</span></td>';
echo '">'.($sat->orbit ?? __('unknown')).'</span></td>';
?>
<td style="text-align: center; vertical-align: middle;"><?php echo htmlentities($sat->modename ?? '') ?></td>
<?php echo '<td style="text-align: center; vertical-align: middle;">';