Fetch and save info about authors.
This commit is contained in:
BIN
data.sample.db
BIN
data.sample.db
Binary file not shown.
@@ -7,15 +7,15 @@ $db = new SQLite3('data.db');
|
||||
if (isset($_GET['category']) && strlen($_GET['category'])) {
|
||||
$stmt = $db->prepare('SELECT * FROM book WHERE category_slug = :category_slug');
|
||||
$stmt->bindValue(':category_slug', $_GET['category'], SQLITE3_TEXT);
|
||||
} elseif (isset($_POST['search']) && isset($_POST['title']) && !empty($_POST['title'])) {
|
||||
} elseif (isset($_GET['search']) && isset($_GET['search_title']) && !empty($_GET['search_title'])) {
|
||||
$stmt = $db->prepare('SELECT * FROM book WHERE title like :search');
|
||||
$stmt->bindValue(':search', '%' . $_POST['title'] . '%', SQLITE3_TEXT);
|
||||
$stmt->bindValue(':search', '%' . $_GET['search_title'] . '%', SQLITE3_TEXT);
|
||||
} else {
|
||||
$stmt = $db->prepare('SELECT * FROM book ');
|
||||
}
|
||||
$result = $stmt->execute();
|
||||
|
||||
echo "<form method='POST'><input type='text' name='title' value='" . ($_POST['title'] ?? '') . "' /><button type='submit' name='search'>Search</button><a href='/'>Clear</a></form>";
|
||||
echo "<form method='get'><input type='text' name='search_title' value='" . ($_GET['search_title'] ?? '') . "' /><button type='submit' name='search'>Search</button><a href='/'>Clear</a></form>";
|
||||
|
||||
|
||||
echo '<table style="width: 100%">';
|
||||
|
||||
50
packt.php
50
packt.php
@@ -96,6 +96,56 @@ function getBookInfo($bookUrl)
|
||||
}
|
||||
|
||||
|
||||
$db = new SQLite3('data.db');
|
||||
|
||||
//$stmt = $db->prepare('SELECT * FROM book order by random() limit 1 ');
|
||||
$stmt = $db->prepare('SELECT * FROM book');
|
||||
$booksResult = $stmt->execute();
|
||||
|
||||
|
||||
//$bookData = $result->fetchArray(SQLITE3_ASSOC);
|
||||
echo '<pre>';
|
||||
while ($book = $booksResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$bookInfo = getBookInfo($book['url']);
|
||||
|
||||
// print_r($book);
|
||||
|
||||
foreach ($bookInfo['authors'] as $author) {
|
||||
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM author WHERE name = :name and bio = :bio');
|
||||
$stmt->bindValue(':name', trim($author['name']), SQLITE3_TEXT);
|
||||
$stmt->bindValue(':bio', trim(implode(' ', $author['bio'])), SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$authorData = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if (!$authorData) {
|
||||
$stmt = $db->prepare('INSERT INTO author(name, bio) VALUES (:name, :bio)');
|
||||
$stmt->bindValue(':name', trim($author['name']), SQLITE3_TEXT);
|
||||
$stmt->bindValue(':bio', trim(implode(' ', $author['bio'])), SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$stmt = $db->prepare('select seq from sqlite_sequence where name="author"');
|
||||
$result = $stmt->execute();
|
||||
$seqData = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO book_author(book_id, author_id) VALUES (:book_id, :author_id)');
|
||||
$stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':author_id', $seqData['seq'], SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
}
|
||||
var_dump($authorData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//print_r($bookData);
|
||||
//print_r($bookInfo);
|
||||
echo '</pre>';
|
||||
|
||||
die();
|
||||
|
||||
|
||||
$return = c('https://www.packtpub.com/', $loginData);
|
||||
$return = c('https://www.packtpub.com/account/my-ebooks');
|
||||
$document = new Document($return);
|
||||
|
||||
Reference in New Issue
Block a user