Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Apr 7, 2024
1 parent 9f74ff4 commit ec907bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions scripts/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ def insert_book_to_notion(books, index, bookId):
readInfo.update(readInfo.get("readDetail", {}))
readInfo.update(readInfo.get("bookInfo", {}))
book.update(readInfo)
cover = book.get("cover")
if cover.startswith("http"):
if not cover.endswith(".jpg"):
cover = utils.upload_cover(cover)
else:
cover = cover.replace("/s_", "/t7_")
else:
cover = BOOK_ICON_URL
isbn = book.get("isbn")
if isbn and isbn.strip():
douban_url = get_douban_url(isbn)
if douban_url:
book["douban_url"] = douban_url
book["封面"] = cover
book["阅读进度"] = (
100 if (book.get("markedStatus") == 4) else book.get("readingProgress", 0)
) / 100
Expand Down Expand Up @@ -98,6 +84,20 @@ def insert_book_to_notion(books, index, bookId):
book["开始阅读时间"] = book.get("beginReadingDate")
book["最后阅读时间"] = book.get("lastReadingDate")
if bookId not in notion_books:
cover = book.get("cover")
if cover.startswith("http"):
if not cover.endswith(".jpg"):
cover = utils.upload_cover(cover)
else:
cover = cover.replace("/s_", "/t7_")
else:
cover = BOOK_ICON_URL
book["封面"] = cover
isbn = book.get("isbn")
if isbn and isbn.strip():
douban_url = get_douban_url(isbn)
if douban_url:
book["douban_url"] = douban_url
book["书名"] = book.get("title")
book["BookId"] = book.get("bookId")
book["ISBN"] = book.get("isbn")
Expand Down Expand Up @@ -129,8 +129,7 @@ def insert_book_to_notion(books, index, bookId):
if bookId in notion_books:
result = notion_helper.update_page(
page_id=notion_books.get(bookId).get("pageId"),
properties=properties,
icon=utils.get_icon(book.get("封面")),
properties=properties
)
else:
result = notion_helper.create_page(
Expand Down
2 changes: 1 addition & 1 deletion scripts/notion_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def update_book_page(self, page_id, properties):
@retry(stop_max_attempt_number=3, wait_fixed=5000)
def update_page(self, page_id, properties, icon):
return self.client.pages.update(
page_id=page_id, icon=icon, properties=properties
page_id=page_id, properties=properties
)

@retry(stop_max_attempt_number=3, wait_fixed=5000)
Expand Down

0 comments on commit ec907bf

Please sign in to comment.