Fetch and save info about authors.
This commit is contained in:
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/account/my-ebooks');
|
||||
$document = new Document($return);
|
||||
@@ -155,7 +205,7 @@ VALUES (:nid, :title, :isbn, :img, :url, :datepublished, :numberofpages, :revie
|
||||
$stmt->bindValue(':code', $bookData['code'], SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
}
|
||||
echo $dl.' - ';
|
||||
echo $dl . ' - ';
|
||||
if ($dl > 500) {
|
||||
// var_dump($dl);
|
||||
die();
|
||||
@@ -171,7 +221,7 @@ function downloadBook($url)
|
||||
$directory = directoryNameFromPath($url);
|
||||
$fullUrl = resolveBookUrl($url);
|
||||
|
||||
echo ($fullUrl)."\n";
|
||||
echo ($fullUrl) . "\n";
|
||||
// var_dump($localPath);
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
|
||||
Reference in New Issue
Block a user