124 lines
1.8 KiB
PHP
Raw Normal View History

2023-11-16 13:26:01 +02:00
<?php
// Init helper
function _exec(
string $processor,
string $command
): mixed
{
if (false !== exec(sprintf('%s %s', $processor, $command), $output))
{
$rows = [];
foreach($output as $row)
{
$rows[] = $row;
}
if ($result = @json_decode(implode(PHP_EOL, $rows)))
{
return $result;
}
}
return false;
}
2023-11-16 22:17:37 +02:00
// Get clitoris
$clitoris = _exec(
2023-11-16 13:26:01 +02:00
$argv[1],
sprintf(
2023-11-16 22:17:37 +02:00
'%s %s "_CLITOR_IS_"',
'keva_get',
2023-11-16 13:26:01 +02:00
$argv[2]
)
);
2023-11-16 22:17:37 +02:00
print_r(
$clitoris
);
2023-11-16 13:26:01 +02:00
2023-11-16 22:17:37 +02:00
if (empty($clitoris->value))
2023-11-16 13:26:01 +02:00
{
2023-11-16 22:17:37 +02:00
exit(
sprintf(
'%s does not contain _CLITOR_IS_' . PHP_EOL,
$argv[2]
)
);
2023-11-16 13:26:01 +02:00
}
2023-11-16 22:17:37 +02:00
if (!$clitoris = @json_decode(
$clitoris->value
))
{
exit(
sprintf(
'could not decode _CLITOR_IS_ of %s' . PHP_EOL,
$argv[2]
)
);
}
2023-11-16 13:26:01 +02:00
2023-11-16 22:17:37 +02:00
if ($clitoris->version !== '1.0')
{
exit(
sprintf(
'_CLITOR_IS_ of %s not compatible!' . PHP_EOL,
$argv[2]
)
);
}
2023-11-16 13:26:01 +02:00
2023-11-16 22:17:37 +02:00
if (empty($clitoris->file->name))
{
exit(
sprintf(
'_CLITOR_IS_ format issue for %s!' . PHP_EOL,
$argv[2]
)
);
}
2023-11-16 13:26:01 +02:00
// Merge content data
2023-11-16 22:17:37 +02:00
$pieces = [];
foreach (
_exec(
$argv[1],
sprintf(
'%s %s "\d+"',
'keva_filter',
$argv[2]
)
) as $piece)
2023-11-16 13:26:01 +02:00
{
2023-11-16 22:17:37 +02:00
$pieces[$piece->key] = $piece->value;
print_r(
$piece
);
2023-11-16 13:26:01 +02:00
}
2023-11-16 22:17:37 +02:00
ksort(
$pieces
);
2023-11-16 13:26:01 +02:00
// Save merged data to destination
$filename = isset($argv[3]) ? $argv[3] : sprintf(
2023-11-16 22:17:37 +02:00
'%s/../data/import/[kevacoin][%s]%s',
2023-11-16 13:26:01 +02:00
__DIR__,
$argv[2],
2023-11-16 22:17:37 +02:00
$clitoris->file->name
2023-11-16 13:26:01 +02:00
);
file_put_contents(
$filename,
base64_decode(
2023-11-16 22:17:37 +02:00
implode('', $pieces)
2023-11-16 13:26:01 +02:00
)
);
echo sprintf(
'saved to %s' . PHP_EOL,
$filename
);