Script to import bible text from JSON file
This commit is contained in:
parent
ee9bc8cf4e
commit
23c89bdb24
26
bin/import-bible.php
Normal file
26
bin/import-bible.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
$bible = json_decode(file_get_contents(dirname(__DIR__).'/var/esv-bible.json'));
|
||||
$db = new PDO('sqlite:'.dirname(__DIR__).'/var/data.db');
|
||||
|
||||
foreach ($bible as $book => $data) {
|
||||
$stmt = $db->prepare('INSERT INTO bible (id, book, chapter, verse, content, book_index) VALUES (:id, :book, :chapter, :verse, :content, :book_index)');
|
||||
|
||||
foreach ($data->text as $chapter => $verses) {
|
||||
foreach ($verses as $verse => $text) {
|
||||
print "{$book} {$chapter}:{$verse}".PHP_EOL;
|
||||
$stmt->execute([
|
||||
'id' => Uuid::v4(),
|
||||
'book' => $book,
|
||||
'chapter' => $chapter,
|
||||
'verse' => ($verse + 1),
|
||||
'content' => $text,
|
||||
'book_index' => $data->index
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user