From c6444317e6717d55006d1b0a82385dd2b984fc23 Mon Sep 17 00:00:00 2001
From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com>
Date: Wed, 1 May 2024 21:06:47 +0200
Subject: [PATCH] Added timestamp to table. Added parser.
---
application/controllers/Update.php | 41 ++++++++++++++++++++++++
application/migrations/196_tle_table.php | 5 +++
2 files changed, 46 insertions(+)
diff --git a/application/controllers/Update.php b/application/controllers/Update.php
index 542a4e380..79df6c015 100644
--- a/application/controllers/Update.php
+++ b/application/controllers/Update.php
@@ -578,5 +578,46 @@ class Update extends CI_Controller {
}
}
+ public function update_tle() {
+ $mtime = microtime();
+ $mtime = explode(" ",$mtime);
+ $mtime = $mtime[1] + $mtime[0];
+ $starttime = $mtime;
+
+ $file = 'https://www.amsat.org/tle/dailytle.txt';
+
+ $handle = fopen($file, "r");
+ if ($handle === FALSE) {
+ echo "Something went wrong with fetching the Amsat TLE file";
+ return;
+ }
+ $this->db->empty_table("tle");
+ $i = 0;
+ $satname = '';
+ $tleline1 = '';
+ $tleline2 = '';
+ while (($line = fgets($handle)) !== false) {
+ $i++;
+ $satname = $line;
+ $tleline1 = fgets($handle);
+ $tleline2 = fgets($handle);
+
+ $sql = "INSERT INTO tle (satelliteid, tle) select id, '" . $tleline1 . "\n" . $tleline2 . "' from satellite where name = '" . $satname . "'";
+ $this->db->query($sql);
+ }
+ fclose($handle);
+
+ $mtime = microtime();
+ $mtime = explode(" ",$mtime);
+ $mtime = $mtime[1] + $mtime[0];
+ $endtime = $mtime;
+ $totaltime = ($endtime - $starttime);
+ echo "This page was created in ".$totaltime." seconds
";
+ echo "Records inserted: " . $i . "
";
+ $datetime = new DateTime("now", new DateTimeZone('UTC'));
+ $datetime = $datetime->format('Ymd h:i');
+ $this->optionslib->update('tle_update', $datetime , 'no');
+ }
+
}
?>
diff --git a/application/migrations/196_tle_table.php b/application/migrations/196_tle_table.php
index 9f923e41b..57b00c2c5 100644
--- a/application/migrations/196_tle_table.php
+++ b/application/migrations/196_tle_table.php
@@ -26,6 +26,11 @@ class Migration_tle_table extends CI_Migration {
'type' => 'TEXT',
'null' => TRUE,
),
+ 'updated' => array(
+ 'type' => 'timestamp',
+ 'null' => false,
+ 'default' => 'CURRENT_TIMESTAMP'
+ ),
));
$this->dbforge->add_key('id', TRUE);