php-dataset/bin/dataset-info

46 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2022-10-30 17:38:43 +00:00
#!/usr/bin/env php
<?php
foreach ([
2022-10-30 22:21:53 +00:00
__DIR__."/..",
__DIR__."/../..",
2022-10-30 22:21:53 +00:00
__DIR__."/../../..",
2022-10-30 17:38:43 +00:00
] as $dir) {
if (file_exists($dir."/autoload.php")) {
2022-10-30 22:02:14 +00:00
define("COMPOSER_VENDOR_PATH", $dir);
2022-10-30 17:38:43 +00:00
require_once $dir."/autoload.php";
} elseif (file_exists($dir."/vendor/autoload.php")) {
define("COMPOSER_VENDOR_PATH", $dir."/vendor");
require_once $dir."/vendor/autoload.php";
2022-10-30 17:38:43 +00:00
}
}
$datasetManager = new NoccyLabs\Dataset\DatasetManager();
$datasets = $datasetManager->getAvailableDatasets();
function _printf(string $fmt, ...$args): void {
$out = sprintf($fmt, ...$args);
if (!posix_isatty(STDOUT)) {
$out = preg_replace("<\e\\[[0-9;]+m>", "", $out);
}
echo $out;
}
2022-10-30 17:38:43 +00:00
foreach ($datasets as $dataset) {
_printf("Identifier: \e[36m%s\e[35m#\e[36;1m%s\e[0m\n", $dataset->getPackageName(), $dataset->getDatasetName());
// $dataset->getIdentifier()."\n";
_printf(" Package: \e[33m%s\e[0m\n", $dataset->getPackageName());
_printf(" Dataset: \e[33m%s\e[0m\n", $dataset->getDatasetName());
_printf(" Version: \e[33m%s\e[0m\n", $dataset->getVersion());
2022-10-30 22:02:14 +00:00
$reader = $dataset->open();
$rows = 0;
$headers = null;
foreach ($reader as $row) {
if (!$headers) $headers = array_keys($row);
$rows++;
}
_printf(" Rows: \e[33m%d\e[0m\n", $rows);
_printf(" Fields: \e[32;1m%s\e[0m\n", join("\e[0m\n \e[32;1m",$headers));
2022-10-30 17:38:43 +00:00
}