From a0a52fe7bed8066c70b24e10367080df4f9e14c5 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 26 Oct 2022 22:23:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B5=D0=BC=D0=BE-=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=84=D0=BE=D1=82=D0=BE=D0=B3=D1=80=D0=B0=D1=84=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=BC=D0=B0=D1=80=D1=81=D0=B0=20=D1=81=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=80=D1=81=D0=BE=D1=85=D0=BE=D0=B4=D0=B0=20=D0=BA=D1=8C=D1=8E?= =?UTF-8?q?=D1=80=D0=B8=D0=BE=D1=81=D0=B8=D1=82=D0=B8=20=D1=87=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B7=20NASA=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.php | 6 +++ core/lib/Core/MQTasks.class.php | 71 ++++++++++++++++++++++++++++++ telegramHandler.php | 2 +- test2.php | 77 +++++++++++++++------------------ 4 files changed, 112 insertions(+), 44 deletions(-) diff --git a/core/config.php b/core/config.php index 0dd78ba..817400e 100644 --- a/core/config.php +++ b/core/config.php @@ -153,3 +153,9 @@ */ const SERVER_EMAIL_NAME = 'Delta Framework'; + /** + * API ключ NASA + */ + const NASA_API = '5qRQx4su8if3zVeweadnbegxcs6gxG9pgRtB1Tmu'; + + const NASA_API_2 = '3vGS2dOB7zd9Jyyrj3dNU0cTkfU4YRRh4M8SK6jl'; diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index 7168062..d62cb77 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -349,4 +349,75 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' $res = file_get_contents('https://dev.it-stories.ru/test.php?cmd=' . $cmd . '&' . http_build_query($params)); return $res; } + + public static function getUser() + { + //sleep(10); + $res = file_get_contents('https://randomuser.me/api/'); + $res = json_decode($res, true, 512, JSON_THROW_ON_ERROR); + $result = [ + 'gender' => $res['results'][0]['gender'], + 'name' => $res['results'][0]['name'], + 'email' => $res['results'][0]['email'], + 'login' => $res['results'][0]['login'], + ]; + //sendTelegram(print_r($res['results'][0]['login'], true)); + return $result; + } + + public static function getSolImages(?int $sol = null) + { + $result = []; + $needGet = true; + if ($sol === null) { + $sol = 1; + } + $page = 1; + + while ($needGet) { + $res = file_get_contents( + 'https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=' . $sol . '&page=' . $page . '&api_key=3vGS2dOB7zd9Jyyrj3dNU0cTkfU4YRRh4M8SK6jl' + );//5qRQx4su8if3zVeweadnbegxcs6gxG9pgRtB1Tmu'); + $res = json_decode($res, true); + if (isset($res['photos']) && !empty($res['photos'])) { + foreach ($res['photos'] as $arImage) { + $result[] = [ + 'date' => $arImage['earth_date'], + 'src' => $arImage['img_src'], + ]; + } + $page++; + } else { + $needGet = false; + } + } + return $result; + } + + public static function saveSolImages($sol) + { + $counter = 0; + $files = []; + $res = self::getSolImages($sol); + + if (empty($res)) { + throw new CoreException('Изображений с ровера за ' . $sol . ' сол нет'); + } + foreach ($res as $arImage) { + $folder = 'ftp://admin:j2medit@10.8.0.2/mars/' . $arImage['date']; + if (!file_exists($folder)) { + if (!mkdir($folder) && !is_dir($folder)) { + throw new CoreException('Папку "' . $folder . '" не удалось создать'); + } + } + if (copy($arImage['src'], $folder . '/' . basename($arImage['src']))) { + $counter++; + $files[] = '/mars/' . $arImage['date'] . '/' . basename($arImage['src']); + //throw new CoreException('Не удалось сохранить файл "' . $folder . '/' . basename($arImage['src']) . '" не удалось создать'); + } + sleep(5); + } + return ['count' => $counter, 'files' => $files]; + } + } \ No newline at end of file diff --git a/telegramHandler.php b/telegramHandler.php index 6b90d5d..75a24ec 100644 --- a/telegramHandler.php +++ b/telegramHandler.php @@ -18,4 +18,4 @@ //$res = $tg->setChat(TELEGRAM_ADMIN_CHAT_ID)->updateMessage(121, ''); - sendTelegram(print_r($data, true)); \ No newline at end of file + //sendTelegram(print_r($data, true)); \ No newline at end of file diff --git a/test2.php b/test2.php index 5d54bbd..d4dcb87 100644 --- a/test2.php +++ b/test2.php @@ -1,51 +1,42 @@ $arImage['earth_date'], + 'src' => $arImage['img_src'], + ]; + } + $page++; + } else { + $needGet = false; + } } + return $result; } - $end = microtime(true); - $deltaTwo = $end - $start; - /**********************/ - $start = microtime(true); - // Проверка сравнением в булевым - for ($i = 0; $i < $count; $i++) { - if ($varFalse === false) { - // пустота - } - } - $end = microtime(true); - $deltaThree = $end - $start; - /**********************/ + + ?> -Тестирование условий с количеством выполнения
- - - - - -
ТестированиеВремя
Эталон
Инверсия
Сравнение с bool
\ No newline at end of file +
+
'; + } + ?> +