Exemplo n.º 1
0
    def post(self):
        isbn = self.request.get('isbn')
        if not isbn:
            return

        try:
            b = douban.get_book_by_isbn(isbn)
        except Exception:
            return

        if not b:
            return

        b_db = Book.get_by_isbn(isbn)
        if b_db:
            b_db.update_to(b)
        return
Exemplo n.º 2
0
    def _load(self, user, isbn, reload, tjlib=False):
        """ Load a book from datastore or from douban.
            @param reload: directly load from douban, no matter whether there is in datastore.
            @param tjlib: whether to also load Tongji Library status when reloading.
            @return: a BookRelated object
        """
        if not reload:
            # everything here
            return books.BookRelated.get_by_user_isbn(user, isbn)

        basic_book = douban.get_book_by_isbn(isbn)
        full = douban.get_book_all_by_id(basic_book.douban_id, user)
        # douban API may have a bug: not providing summary somehow
        full.book.summary = basic_book.summary
        full.merge_into_datastore(user)

        if tjlib:
            url, datas = tongji.get_by_isbn(isbn)
            full.book.set_tongji_info(url, datas)

        return full