public function updateBook(Book &$dbBook) { $html = PtHttpCk101::getBookContentPage($dbBook->id, 1); $book = PtParserCk101::parseBookFromThread($html); if ($book == null) { $dbBook->update_time = time(); $this->db->editBook(Book::toArray($dbBook)); $this->d("Error! The Book not exists. {$dbBook->id} {$dbBook->name}"); return; } $book->current_pages = max($dbBook->current_pages, 1); if ($book->posts == 0) { $this->d("Error! Can not parse pages! {$book->id}, {$book->current_pages}/{$book->pages}, {$book->name}"); return; } do { $this->d("Start to update book {$book->id}, {$book->current_pages}/{$book->pages}, {$book->name}"); if ($book->current_pages != 1) { // page 1 is already downloaded $html = PtHttpCk101::getBookContentPage($dbBook->id, $book->current_pages); } if ($html == null) { $this->d("Get content text error! Ignore this book"); break; } $text = PtParserCk101::parseContentFromThread($html); PtFile::saveBook($book->id, $book->current_pages, $text); $this->db->editBook(Book::toArray($book)); sleep(self::QUERY_SLEEP); } while (++$book->current_pages <= $book->pages); }
public function testgetBookContentPage() { PtHttpCk101::getBookContentPage(3347713, 1); }