From 912b4b650d87a7e0e021837dceba792cf099e37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pleva=C4=8D?= Date: Sun, 1 Oct 2023 14:27:08 +0200 Subject: [PATCH] Added support for tle update --- web/API/cron.php | 39 +++++++++++++++++++++++++++++++++++++++ web/API/main.php | 1 + 2 files changed, 40 insertions(+) create mode 100644 web/API/cron.php diff --git a/web/API/cron.php b/web/API/cron.php new file mode 100644 index 0000000..f3ec5e0 --- /dev/null +++ b/web/API/cron.php @@ -0,0 +1,39 @@ +getAll()->values as $target) { + + $locator = $target->locator->get(); + if (array_key_exists("tle", $locator)) { + //get NORAD of objects + $norad = explode(" ", $locator["tle"]["line2"])[1]; + + //have norad now get data from celestrak + //https://celestrak.org/NORAD/elements/gp.php?CATNR={norad}&FORMAT=tle + + $newTle = file_get_contents("https://celestrak.org/NORAD/elements/gp.php?CATNR={$norad}&FORMAT=tle"); + $newTle = explode("\n", $newTle); + + if (count($newTle) == 3) { //tle loaded + $locator["tle"]["line1"] = $newTle[1]; + $locator["tle"]["line2"] = $newTle[2]; + + $updated[] = ["name" => $target->name->get(), "norad" => $norad]; + + $target->locator->set($locator); + $target->commit(); + } + } + } + + return $updated; + } \ No newline at end of file diff --git a/web/API/main.php b/web/API/main.php index 977203c..8d4ce5c 100644 --- a/web/API/main.php +++ b/web/API/main.php @@ -13,6 +13,7 @@ //register API functions include_once(__DIR__ . "/observations.php"); include_once(__DIR__ . "/stations.php"); + include_once(__DIR__ . "/cron.php"); //init API $api->serve($router->getArgs()); \ No newline at end of file