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'])) {
|
if (isset($_GET['category']) && strlen($_GET['category'])) {
|
||||||
$stmt = $db->prepare('SELECT * FROM book WHERE category_slug = :category_slug');
|
$stmt = $db->prepare('SELECT * FROM book WHERE category_slug = :category_slug');
|
||||||
$stmt->bindValue(':category_slug', $_GET['category'], SQLITE3_TEXT);
|
$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 = $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 {
|
} else {
|
||||||
$stmt = $db->prepare('SELECT * FROM book ');
|
$stmt = $db->prepare('SELECT * FROM book ');
|
||||||
}
|
}
|
||||||
$result = $stmt->execute();
|
$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%">';
|
echo '<table style="width: 100%">';
|
||||||
|
|||||||
54
packt.php
54
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/', $loginData);
|
||||||
$return = c('https://www.packtpub.com/account/my-ebooks');
|
$return = c('https://www.packtpub.com/account/my-ebooks');
|
||||||
$document = new Document($return);
|
$document = new Document($return);
|
||||||
@@ -155,7 +205,7 @@ VALUES (:nid, :title, :isbn, :img, :url, :datepublished, :numberofpages, :revie
|
|||||||
$stmt->bindValue(':code', $bookData['code'], SQLITE3_TEXT);
|
$stmt->bindValue(':code', $bookData['code'], SQLITE3_TEXT);
|
||||||
$result = $stmt->execute();
|
$result = $stmt->execute();
|
||||||
}
|
}
|
||||||
echo $dl.' - ';
|
echo $dl . ' - ';
|
||||||
if ($dl > 500) {
|
if ($dl > 500) {
|
||||||
// var_dump($dl);
|
// var_dump($dl);
|
||||||
die();
|
die();
|
||||||
@@ -171,7 +221,7 @@ function downloadBook($url)
|
|||||||
$directory = directoryNameFromPath($url);
|
$directory = directoryNameFromPath($url);
|
||||||
$fullUrl = resolveBookUrl($url);
|
$fullUrl = resolveBookUrl($url);
|
||||||
|
|
||||||
echo ($fullUrl)."\n";
|
echo ($fullUrl) . "\n";
|
||||||
// var_dump($localPath);
|
// var_dump($localPath);
|
||||||
if (!is_dir($directory)) {
|
if (!is_dir($directory)) {
|
||||||
mkdir($directory, 0777, true);
|
mkdir($directory, 0777, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user