diff --git a/data.sample.db b/data.sample.db
index b288229..9a92003 100644
Binary files a/data.sample.db and b/data.sample.db differ
diff --git a/index.php b/index.php
index ea3b05b..919bdf2 100644
--- a/index.php
+++ b/index.php
@@ -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 "
";
+echo "";
echo '';
diff --git a/packt.php b/packt.php
index 7db6e55..fee2065 100644
--- a/packt.php
+++ b/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 '';
+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 '';
+
+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);