демо-метод получения фотографий марса с марсохода кьюриосити через NASA API
This commit is contained in:
1 parent
3560453e2d
commit
a0a52fe7be
4 files changed
+112
-44
No files matched your search
@@ -153,3 +153,9 @@
|
|||||||
*/
|
*/
|
||||||
const SERVER_EMAIL_NAME = 'Delta Framework';
|
const SERVER_EMAIL_NAME = 'Delta Framework';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ключ NASA
|
||||||
|
*/
|
||||||
|
const NASA_API = '5qRQx4su8if3zVeweadnbegxcs6gxG9pgRtB1Tmu';
|
||||||
|
|
||||||
|
const NASA_API_2 = '3vGS2dOB7zd9Jyyrj3dNU0cTkfU4YRRh4M8SK6jl';
|
||||||
@@ -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));
|
$res = file_get_contents('https://dev.it-stories.ru/test.php?cmd=' . $cmd . '&' . http_build_query($params));
|
||||||
return $res;
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -18,4 +18,4 @@
|
|||||||
//$res = $tg->setChat(TELEGRAM_ADMIN_CHAT_ID)->updateMessage(121, '');
|
//$res = $tg->setChat(TELEGRAM_ADMIN_CHAT_ID)->updateMessage(121, '');
|
||||||
|
|
||||||
|
|
||||||
sendTelegram(print_r($data, true));
|
//sendTelegram(print_r($data, true));
|
||||||
@@ -1,51 +1,42 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$timer1 = $timer2 = 0;
|
function getSolImages(?int $sol = null)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
$needGet = true;
|
||||||
|
if ($sol === null) {
|
||||||
|
$sol = 1;
|
||||||
|
}
|
||||||
|
$page = 1;
|
||||||
|
|
||||||
$varTrue = true;
|
while($needGet) {
|
||||||
$varFalse = false;
|
$res = file_get_contents('https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=' . $sol . '&page=' . $page . '&api_key=5qRQx4su8if3zVeweadnbegxcs6gxG9pgRtB1Tmu');
|
||||||
|
$res = json_decode($res, true);
|
||||||
$count = 100000000;
|
if (isset($res['photos']) && !empty($res['photos'])) {
|
||||||
|
foreach($res['photos'] as $arImage) {
|
||||||
|
$result[] = [
|
||||||
/**********************/
|
'date' => $arImage['earth_date'],
|
||||||
$start = microtime(true);
|
'src' => $arImage['img_src'],
|
||||||
// Проверка эталона
|
];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
}
|
||||||
if ($varTrue) {
|
$page++;
|
||||||
// пустота
|
} else {
|
||||||
|
$needGet = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$end = microtime(true);
|
return $result;
|
||||||
$deltaOne = $end - $start;
|
}
|
||||||
|
|
||||||
|
|
||||||
/**********************/
|
|
||||||
$start = microtime(true);
|
|
||||||
// Проверка инверсии
|
|
||||||
for ($i = 0; $i < $count; $i++) {
|
|
||||||
if (!$varFalse) {
|
|
||||||
// пустота
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$end = microtime(true);
|
|
||||||
$deltaTwo = $end - $start;
|
|
||||||
/**********************/
|
|
||||||
|
|
||||||
$start = microtime(true);
|
|
||||||
// Проверка сравнением в булевым
|
|
||||||
for ($i = 0; $i < $count; $i++) {
|
|
||||||
if ($varFalse === false) {
|
|
||||||
// пустота
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$end = microtime(true);
|
|
||||||
$deltaThree = $end - $start;
|
|
||||||
/**********************/
|
|
||||||
?>
|
?>
|
||||||
<b>Тестирование условий с количеством выполнения <?= $count ?></b><br>
|
<div style="display:flex; flex-wrap: wrap">
|
||||||
<table border="1px">
|
<?php
|
||||||
<tr style="font-weight: bold"><td>Тестирование</td><td>Время</td></tr>
|
$sol = $_REQUEST['sol'] ?: 1;
|
||||||
<tr><td>Эталон</td><td><?= $deltaOne ?></td></tr>
|
$res = getSolImages($sol);
|
||||||
<tr><td>Инверсия</td><td><?= $deltaTwo ?></td></tr>
|
|
||||||
<tr><td>Сравнение с bool</td><td><?= $deltaThree ?></td></tr>
|
foreach ($res as $item) {
|
||||||
</table>
|
echo '<div><img src="' . $item['src'] . '" width="300px"> </div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
Reference in new issue
Block a user