Informations abut ToC, star and unstar book.

This commit is contained in:
krzysiej
2018-07-03 10:38:29 +02:00
parent 347451dd98
commit 42beb193e4
3 changed files with 361 additions and 100 deletions

Binary file not shown.

196
index.php
View File

@@ -1,27 +1,183 @@
<?php <?php
include 'vendor/autoload.php'; include 'vendor/autoload.php';
set_time_limit(-1); set_time_limit(-1);
$db = new SQLite3('data.db'); $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 b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE category_slug = :category_slug GROUP BY b.id ');
$stmt->bindValue(':category_slug', $_GET['category'], SQLITE3_TEXT); $stmt->bindValue(':category_slug', $_GET['category'], SQLITE3_TEXT);
} elseif (isset($_GET['search']) && isset($_GET['search_title']) && !empty($_GET['search_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 b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE title like :search GROUP BY b.id ');
$stmt->bindValue(':search', '%' . $_GET['search_title'] . '%', SQLITE3_TEXT); $stmt->bindValue(':search', '%' . $_GET['search_title'] . '%', SQLITE3_TEXT);
} elseif (isset($_GET['author']) && !empty($_GET['author'])) {
$stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE a.name = :author GROUP BY b.id ');
$stmt->bindValue(':author', $_GET['author'], SQLITE3_TEXT);
} elseif (isset($_GET['book']) && !empty($_GET['book'])) {
$stmt = $db->prepare('SELECT * FROM chapter WHERE book_id = :book');
$stmt->bindValue(':book', $_GET['book'], SQLITE3_INTEGER);
$result = $stmt->execute();
$chaptersArray = [];
while ($chapter = $result->fetchArray(SQLITE3_ASSOC)) {
if (!$chapter['parent_id']) {
$chaptersArray[$chapter['id']] = ['name' => $chapter['name'], 'order' => $chapter['chapter_number'], 'subchapter' => []];
} else {
$chaptersArray[$chapter['parent_id']]['subchapter'][$chapter['chapter_number']] = ['id' => $chapter['id'], 'name' => $chapter['name']];
}
}
$stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE b.id = :book GROUP BY b.id ');
$stmt->bindValue(':book', $_GET['book'], SQLITE3_INTEGER);
} elseif (isset($_GET['star']) && !empty($_GET['star'])) {
$stmt = $db->prepare('SELECT * FROM star WHERE book_id = :book');
$stmt->bindValue(':book', $_GET['star'], SQLITE3_INTEGER);
$result = $stmt->execute();
if ($result->fetchArray(SQLITE3_ASSOC) === false) {
$insertStmt = $db->prepare('INSERT INTO star (book_id, user_id) VALUES (:book_id, :user_id) ');
$insertStmt->bindValue(':book_id', $_GET['star'], SQLITE3_INTEGER);
$insertStmt->bindValue(':user_id', 1, SQLITE3_INTEGER);
$insertStmt->execute();
} else {
$stmt = $db->prepare('DELETE FROM star WHERE book_id = :book');
$stmt->bindValue(':book', $_GET['star'], SQLITE3_INTEGER);
$result = $stmt->execute();
}
if (isset($_SERVER['HTTP_REFERER'])) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
header('Location: /');
}
} else { } else {
$stmt = $db->prepare('SELECT * FROM book '); $stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id GROUP BY b.id');
} }
$result = $stmt->execute(); $result = $stmt->execute();
?>
<style>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
text-decoration: none;
color: #0070de;
}
a:hover {
color: #58abfc;
}
tbody tr:nth-child(2n) {
background: rgba(0, 0, 0, 0.02);
}
tbody tr:hover {
background: rgba(0, 0, 0, 0.04);
}
body {
font-family: arial;
font-size: 0.9em;
line-height: 16px;
}
td {
padding: 2px 15px;
}
form {
margin: 15px 50px;
}
form a {
margin: 0 10px;
}
input[type="text"] {
padding: 5px 15px;
}
button {
padding: 4px 15px;
}
.star {
color: #e4e4e4;
}
.star.on, .star:hover {
color: gold;
text-shadow: 1px 1px 1px #000;
}
.star.off {
}
</style>
<?php
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 "<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%">';
print('<tr> <th>id</th><th>nid</th><th>Title</th><th>Category</th><th>Publish date</th><th>Pages</th><th>Votes</th><th>Rating</th> <th>Pdf</th> <th>Epub</th> <th>Mobi</th> <th>Code</th> </tr>'); print('<thead><tr> <th>nid</th><th></th> <th>Title</th> <th>Category</th> <th style="width: 300px;">Author</th> <th>Publish date</th> <th>Pages</th> <th>Votes</th> <th>Rating</th> <th>Pdf</th> <th>Epub</th> <th>Mobi</th> <th>Code</th> </tr></thead> <tbody>');
while ($resultArray = $result->fetchArray(SQLITE3_ASSOC)) { while ($resultArray = $result->fetchArray(SQLITE3_ASSOC)) {
$pdfUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.pdf'; $pdfUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.pdf';
$epubUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.epub'; $epubUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.epub';
$mobiUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.mobi'; $mobiUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.mobi';
@@ -30,16 +186,34 @@ while ($resultArray = $result->fetchArray(SQLITE3_ASSOC)) {
$codeId = $found[0]; $codeId = $found[0];
$codeUrl = 'books/' . $codeId . '/' . $codeId . '.zip'; $codeUrl = 'books/' . $codeId . '/' . $codeId . '.zip';
} }
printf('<tr> <td>%d</td><td>%d</td><td><a href="http://packtpub.com%s">%s</a></td><td><a href="?category=%s">%s</a></td><td>%s</td><td>%s</td><td>%d</td><td>%.1f</td> <td>%s</td><td>%s</td><td>%s</td><td>%s</td> </tr>',
$resultArray['id'], $resultArray['nid'], $resultArray['url'], $resultArray['title'], $resultArray['category_slug'], $resultArray['category'], $resultArray['datepublished'], $resultArray['numberofpages'], $resultArray['reviewCount'], $resultArray['ratingValue'],
$authorsArray = explode('|', $resultArray['author_name']);
$authors = [];
foreach ($authorsArray as $author) {
$authors[] = '<a href="?author=' . $author . '">' . $author . '</a>';
}
printf('<tr> <td><a href="http://packtpub.com%s">%d</a></td> <td><a class="star %s" href="?star=%d">%s</a></td> <td><a href="?book=%d">%s</a></td> <td><a href="?category=%s">%s</a></td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%d</td> <td>%.1f</td> <td>%s</td> <td>%s</td><td>%s</td><td>%s</td> </tr>',
$resultArray['url'], $resultArray['nid'], $resultArray['star'] ? 'on' : 'off', $resultArray['id'], $resultArray['star'] ? '&#9733' : '&#9734', $resultArray['id'], $resultArray['title'], $resultArray['category_slug'], $resultArray['category'], implode(', ', $authors), $resultArray['datepublished'], $resultArray['numberofpages'], $resultArray['reviewCount'], $resultArray['ratingValue'],
is_file($pdfUrl) ? "<a href='{$pdfUrl}'>pdf</a>" : (strlen($resultArray['pdf']) ? 'nie pobrano' : ''), is_file($pdfUrl) ? "<a href='{$pdfUrl}'>pdf</a>" : (strlen($resultArray['pdf']) ? 'nie pobrano' : ''),
is_file($epubUrl) ? "<a href='{$epubUrl}'>epub</a>" : (strlen($resultArray['epub']) ? 'nie pobrano' : ''), is_file($epubUrl) ? "<a href='{$epubUrl}'>epub</a>" : (strlen($resultArray['epub']) ? 'nie pobrano' : ''),
is_file($mobiUrl) ? "<a href='{$mobiUrl}'>mobi</a>" : (strlen($resultArray['mobi']) ? 'nie pobrano' : ''), is_file($mobiUrl) ? "<a href='{$mobiUrl}'>mobi</a>" : (strlen($resultArray['mobi']) ? 'nie pobrano' : ''),
is_file($codeUrl) ? "<a href='{$codeUrl}'>zip</a>" : (strlen($resultArray['code']) ? 'nie pobrano' : '') is_file($codeUrl) ? "<a href='{$codeUrl}'>zip</a>" : (strlen($resultArray['code']) ? 'nie pobrano' : '')
); );
if ($resultArray) { if (isset($chaptersArray) && $chaptersArray != []) {
$x = $resultArray; $table = '<table class="toc">';
foreach ($chaptersArray as $chapter) {
$table .= '<tr class="chapter"><td colspan="2">' . $chapter['name'] . '</td></tr>';
foreach ($chapter['subchapter'] as $subchapter) {
$table .= '<tr class="subchapter"><td></td><td>' . $subchapter['name'] . '</td></tr>';
}
}
$table .= '</table>';
echo $table;
} }
// if ($resultArray) {
// $x = $resultArray;
// }
} }
echo '</table>'; echo '</tbody></table>';

265
packt.php
View File

@@ -46,7 +46,6 @@ function c($url, $post = [], $localFilePath = null)
return $server_output; return $server_output;
} }
function resolveBookUrl($bookUrl) function resolveBookUrl($bookUrl)
{ {
return 'https://www.packtpub.com/' . trim(str_replace('https://www.packtpub.com/', '', $bookUrl), '/'); return 'https://www.packtpub.com/' . trim(str_replace('https://www.packtpub.com/', '', $bookUrl), '/');
@@ -96,122 +95,210 @@ function getBookInfo($bookUrl)
} }
function saveBookChapters($data, $bookId)
{
$db = new SQLite3('data.db');
print_r($data);
foreach ($data['toc'] as $chapterNumber => $chapter) {
$stmt = $db->prepare('REPLACE INTO chapter (book_id, chapter_number, parent_id, name)
VALUES (:book_id, :chapter_number, :parent_id, :name)');
$stmt->bindValue(':book_id', $bookId, SQLITE3_INTEGER);
$stmt->bindValue(':chapter_number', $chapterNumber + 1, SQLITE3_INTEGER);
$stmt->bindValue(':parent_id', null, SQLITE3_INTEGER);
$stmt->bindValue(':name', $chapter['title'], SQLITE3_TEXT);
$result = $stmt->execute();
$stmt = $db->prepare('select seq from sqlite_sequence where name="chapter"');
$result = $stmt->execute();
$lastInsertedId = $result->fetchArray(SQLITE3_ASSOC);
$lastInsertedId['seq'];
if (isset($chapter['subchapters'])) {
foreach ($chapter['subchapters'] as $subChapterNumber => $subChapterName) {
$stmt = $db->prepare('REPLACE INTO chapter (book_id, chapter_number, parent_id, name)
VALUES (:book_id, :chapter_number, :parent_id, :name)');
$stmt->bindValue(':book_id', $bookId, SQLITE3_INTEGER);
$stmt->bindValue(':chapter_number', $subChapterNumber + 1, SQLITE3_INTEGER);
$stmt->bindValue(':parent_id', $lastInsertedId['seq'], SQLITE3_INTEGER);
$stmt->bindValue(':name', $subChapterName, SQLITE3_TEXT);
$result = $stmt->execute();
}
}
}
}
echo '<pre>';
//$data = getBookInfo('big-data-and-business-intelligence/mastering-blockchain');
//file_put_contents('data.txt', json_encode($data));
//die();
$db = new SQLite3('data.db'); $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();
while ($book = $booksResult->fetchArray(SQLITE3_ASSOC)) {
$data = getBookInfo($book['url']);
// saveBookChapters($data, $book['id']);
// $db = new SQLite3('data.db');
// print_r($data);
foreach ($data['toc'] as $chapterNumber => $chapter) {
$stmt = $db->prepare('REPLACE INTO chapter (book_id, chapter_number, parent_id, name)
VALUES (:book_id, :chapter_number, :parent_id, :name)');
$stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER);
$stmt->bindValue(':chapter_number', $chapterNumber + 1, SQLITE3_INTEGER);
$stmt->bindValue(':parent_id', null, SQLITE3_INTEGER);
$stmt->bindValue(':name', $chapter['title'], SQLITE3_TEXT);
$result = $stmt->execute();
$stmt = $db->prepare('select seq from sqlite_sequence where name="chapter"');
$result = $stmt->execute();
$lastInsertedId = $result->fetchArray(SQLITE3_ASSOC);
$lastInsertedId['seq'];
if (isset($chapter['subchapters'])) {
foreach ($chapter['subchapters'] as $subChapterNumber => $subChapterName) {
$stmt = $db->prepare('REPLACE INTO chapter (book_id, chapter_number, parent_id, name)
VALUES (:book_id, :chapter_number, :parent_id, :name)');
$stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER);
$stmt->bindValue(':chapter_number', $subChapterNumber + 1, SQLITE3_INTEGER);
$stmt->bindValue(':parent_id', $lastInsertedId['seq'], SQLITE3_INTEGER);
$stmt->bindValue(':name', $subChapterName, SQLITE3_TEXT);
$result = $stmt->execute();
}
}
}
}
//$data = json_decode(file_get_contents('data.txt'), 1);
//$bookId = 1;
//print_r($data);
function fetchAuthorsByBooks()
{
$db = new SQLite3('data.db');
//$stmt = $db->prepare('SELECT * FROM book order by random() limit 1 '); //$stmt = $db->prepare('SELECT * FROM book order by random() limit 1 ');
$stmt = $db->prepare('select * from book'); $stmt = $db->prepare('select * from book');
$stmt = $db->prepare('select * from book left join author_book ON book.id = author_book.book_id where author_book.book_id is null and category is not null'); $booksResult = $stmt->execute();
$booksResult = $stmt->execute();
//$bookData = $result->fetchArray(SQLITE3_ASSOC); //$bookData = $result->fetchArray(SQLITE3_ASSOC);
echo '<pre>'; while ($book = $booksResult->fetchArray(SQLITE3_ASSOC)) {
while ($book = $booksResult->fetchArray(SQLITE3_ASSOC)) { $bookInfo = getBookInfo($book['url']);
$bookInfo = getBookInfo($book['url']); foreach ($bookInfo['authors'] as $author) {
$stmt = $db->prepare('SELECT * FROM author WHERE name = :name and bio = :bio');
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', $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(':name', trim($author['name']), SQLITE3_TEXT);
$stmt->bindValue(':bio', $author['bio'], SQLITE3_TEXT); $stmt->bindValue(':bio', $author['bio'], SQLITE3_TEXT);
$result = $stmt->execute(); $result = $stmt->execute();
$authorData = $result->fetchArray(SQLITE3_ASSOC);
$stmt = $db->prepare('select seq from sqlite_sequence where name="author"'); if (!$authorData) {
$result = $stmt->execute(); $stmt = $db->prepare('INSERT INTO author(name, bio) VALUES (:name, :bio)');
$seqData = $result->fetchArray(SQLITE3_ASSOC); $stmt->bindValue(':name', trim($author['name']), SQLITE3_TEXT);
$stmt->bindValue(':bio', $author['bio'], SQLITE3_TEXT);
$result = $stmt->execute();
$stmt = $db->prepare('INSERT INTO author_book(author_id, book_id) VALUES (:author_id, :book_id)'); $stmt = $db->prepare('select seq from sqlite_sequence where name="author"');
$stmt->bindValue(':author_id', $seqData['seq'], SQLITE3_INTEGER); $result = $stmt->execute();
$stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER); $seqData = $result->fetchArray(SQLITE3_ASSOC);
$result = $stmt->execute();
} else { $stmt = $db->prepare('INSERT INTO author_book(author_id, book_id) VALUES (:author_id, :book_id)');
$stmt = $db->prepare('INSERT INTO author_book(author_id, book_id) VALUES (:author_id, :book_id)'); $stmt->bindValue(':author_id', $seqData['seq'], SQLITE3_INTEGER);
$stmt->bindValue(':author_id', $authorData['id'], SQLITE3_INTEGER); $stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER);
$stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER); $result = $stmt->execute();
$result = $stmt->execute(); } else {
$stmt = $db->prepare('INSERT INTO author_book(author_id, book_id) VALUES (:author_id, :book_id)');
$stmt->bindValue(':author_id', $authorData['id'], SQLITE3_INTEGER);
$stmt->bindValue(':book_id', $book['id'], SQLITE3_INTEGER);
$result = $stmt->execute();
}
} }
var_dump($authorData);
} }
} }
//print_r($bookData); function downloadBooks()
//print_r($bookInfo); {
global $loginData;
$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);
// //
//$document = new Document('packt.html', true); //$document = new Document('packt.html', true);
$booksData = []; $booksData = [];
$books = $document->find('.product-line.unseen'); $books = $document->find('.product-line.unseen');
$dl = 0; $dl = 0;
$db = new SQLite3('data.db'); $db = new SQLite3('data.db');
//shuffle($books); //shuffle($books);
foreach ($books as $book) { foreach ($books as $book) {
$bookData = []; $bookData = [];
$bookData['title'] = str_replace(["\r\n"], '', trim($book->first('.title::text'))); $bookData['title'] = str_replace(["\r\n"], '', trim($book->first('.title::text')));
$bookData['nid'] = (int)$book->attr('nid'); $bookData['nid'] = (int)$book->attr('nid');
$bookData['pdf'] = truncateBookUrl($book->first('a[href$=pdf]::attr(href)')); $bookData['pdf'] = truncateBookUrl($book->first('a[href$=pdf]::attr(href)'));
$bookData['epub'] = truncateBookUrl($book->first('a[href$=epub]::attr(href)')); $bookData['epub'] = truncateBookUrl($book->first('a[href$=epub]::attr(href)'));
$bookData['mobi'] = truncateBookUrl($book->first('a[href$=mobi]::attr(href)')); $bookData['mobi'] = truncateBookUrl($book->first('a[href$=mobi]::attr(href)'));
$bookData['code'] = truncateBookUrl($book->first('a[href*=code_download]::attr(href)')); $bookData['code'] = truncateBookUrl($book->first('a[href*=code_download]::attr(href)'));
$bookData['isbn'] = $book->first('div[isbn]::attr(isbn)'); $bookData['isbn'] = $book->first('div[isbn]::attr(isbn)');
$bookData['img'] = $book->first('img[class*=imagecache]::attr(src)'); $bookData['img'] = $book->first('img[class*=imagecache]::attr(src)');
$bookData['url'] = truncateBookUrl($book->first('div[class*=product-thumbnail]')->first('a::attr(href)')); $bookData['url'] = truncateBookUrl($book->first('div[class*=product-thumbnail]')->first('a::attr(href)'));
$stmt = $db->prepare('SELECT id FROM book WHERE nid = :nid'); $stmt = $db->prepare('SELECT id FROM book WHERE nid = :nid');
$stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER);
$result = $stmt->execute();
$resultData = $result->fetchArray(SQLITE3_ASSOC);
$dl += downloadBook($bookData['pdf']);
$dl += downloadBook($bookData['epub']);
$dl += downloadBook($bookData['mobi']);
$dl += downloadBook($bookData['code']);
if (!$resultData) {
$bookData['info'] = getBookInfo($bookData['url']);
$stmt = $db->prepare('REPLACE INTO book (nid, title, isbn, img, url, datepublished, numberofpages, reviewCount, ratingValue, category, pdf, epub, mobi, code)
VALUES (:nid, :title, :isbn, :img, :url, :datepublished, :numberofpages, :reviewCount, :ratingValue, :category, :pdf, :epub, :mobi, :code)');
$stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER); $stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER);
$stmt->bindValue(':title', $bookData['title'], SQLITE3_TEXT);
$stmt->bindValue(':isbn', $bookData['isbn'], SQLITE3_TEXT);
$stmt->bindValue(':img', $bookData['img'], SQLITE3_TEXT);
$stmt->bindValue(':url', $bookData['url'], SQLITE3_TEXT);
$stmt->bindValue(':datepublished', $bookData['info']['datepublished'], SQLITE3_TEXT);
$stmt->bindValue(':numberofpages', $bookData['info']['numberofpages'], SQLITE3_INTEGER);
$stmt->bindValue(':reviewCount', $bookData['info']['reviewCount'], SQLITE3_INTEGER);
$stmt->bindValue(':ratingValue', (float)$bookData['info']['ratingValue'], SQLITE3_FLOAT);
$stmt->bindValue(':category', $bookData['info']['category'], SQLITE3_TEXT);
$stmt->bindValue(':pdf', $bookData['pdf'], SQLITE3_TEXT);
$stmt->bindValue(':epub', $bookData['epub'], SQLITE3_TEXT);
$stmt->bindValue(':mobi', $bookData['mobi'], SQLITE3_TEXT);
$stmt->bindValue(':code', $bookData['code'], SQLITE3_TEXT);
$result = $stmt->execute(); $result = $stmt->execute();
}
echo $dl . ' - ';
if ($dl > 500) {
// var_dump($dl);
die();
}
$resultData = $result->fetchArray(SQLITE3_ASSOC);
$dl += downloadBook($bookData['pdf']);
$dl += downloadBook($bookData['epub']);
$dl += downloadBook($bookData['mobi']);
$dl += downloadBook($bookData['code']);
if (!$resultData) {
$bookData['info'] = getBookInfo($bookData['url']);
$stmt = $db->prepare('REPLACE INTO book (nid, title, isbn, img, url, datepublished, numberofpages, reviewCount, ratingValue, category, pdf, epub, mobi, code)
VALUES (:nid, :title, :isbn, :img, :url, :datepublished, :numberofpages, :reviewCount, :ratingValue, :category, :pdf, :epub, :mobi, :code)');
$stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER);
$stmt->bindValue(':title', $bookData['title'], SQLITE3_TEXT);
$stmt->bindValue(':isbn', $bookData['isbn'], SQLITE3_TEXT);
$stmt->bindValue(':img', $bookData['img'], SQLITE3_TEXT);
$stmt->bindValue(':url', $bookData['url'], SQLITE3_TEXT);
$stmt->bindValue(':datepublished', $bookData['info']['datepublished'], SQLITE3_TEXT);
$stmt->bindValue(':numberofpages', $bookData['info']['numberofpages'], SQLITE3_INTEGER);
$stmt->bindValue(':reviewCount', $bookData['info']['reviewCount'], SQLITE3_INTEGER);
$stmt->bindValue(':ratingValue', (float)$bookData['info']['ratingValue'], SQLITE3_FLOAT);
$stmt->bindValue(':category', $bookData['info']['category'], SQLITE3_TEXT);
$stmt->bindValue(':pdf', $bookData['pdf'], SQLITE3_TEXT);
$stmt->bindValue(':epub', $bookData['epub'], SQLITE3_TEXT);
$stmt->bindValue(':mobi', $bookData['mobi'], SQLITE3_TEXT);
$stmt->bindValue(':code', $bookData['code'], SQLITE3_TEXT);
$result = $stmt->execute();
}
echo $dl . ' - ';
if ($dl > 500) {
// var_dump($dl);
die();
}
}
} }
function downloadBook($url) function downloadBook($url)