1.2 #23
@@ -8,7 +8,6 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
@@ -48,45 +47,32 @@ class IngestBibleCommand extends Command
|
||||
$this->io = new SymfonyStyle($input, $output);
|
||||
$this->dir = $input->getArgument('directory');
|
||||
|
||||
if (!$this->dir) {
|
||||
if (!$this->dir || !file_exists($this->dir)) {
|
||||
$this->io->error('Directory not specific or does not exist');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->io->note("Crawling {$this->dir} and ingesting Bible passages...");
|
||||
|
||||
foreach($this->getFiles() as $file) {
|
||||
$this->io->info("Processing ".basename($file));
|
||||
$this->processFile($file);
|
||||
$json = json_decode(file_get_contents("{$this->dir}/esv-bible.json"));
|
||||
foreach ($json as $book => $data) {
|
||||
$index = $data->index;
|
||||
$chapters = $data->chapters;
|
||||
$label = $data->label;
|
||||
foreach ($data->text as $chapter => $verses) {
|
||||
foreach ($verses as $idx => $verse) {
|
||||
print "$book $chapter:$idx\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function getFiles(): array
|
||||
{
|
||||
$this->files = glob($this->dir . "/*/*.md");
|
||||
|
||||
if(!$this->files || count($this->files) === 0) {
|
||||
$this->io->warning("No files found in this directory\n{$this->dir}");
|
||||
$this->files = [];
|
||||
}
|
||||
natsort($this->files);
|
||||
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
private function processFile(string $file)
|
||||
{
|
||||
$bible = new Bible();
|
||||
|
||||
$match = [];
|
||||
if(preg_match("/([\d]+) \- ([^\/]+)\/\d?[a-zA-Z]+([\d]+)\.md/", $file, $match)) {
|
||||
$ndx = (int) $match[1];
|
||||
$book = str_replace(" ", "", $match[2]);
|
||||
$chapter = (int) $match[3];
|
||||
}
|
||||
|
||||
if (preg_match("/(\d)([^\d]+)/", $book, $match)) {
|
||||
$book = $match[1]." ".$match[2];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user