From 9c9b8b4fd2d4f43da51b800ad1def1add0cbc83f Mon Sep 17 00:00:00 2001 From: malinkang Date: Fri, 19 Apr 2024 09:44:11 +0800 Subject: [PATCH] fix cover --- scripts/book.py | 29 +++++++++++++---------------- scripts/notion_helper.py | 12 +++++++++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/scripts/book.py b/scripts/book.py index de72198cd332..c828ec5dbae9 100644 --- a/scripts/book.py +++ b/scripts/book.py @@ -83,16 +83,10 @@ def insert_book_to_notion(books, index, bookId): book["时间"] = date book["开始阅读时间"] = book.get("beginReadingDate") book["最后阅读时间"] = book.get("lastReadingDate") + cover = book.get("cover").replace("/s_", "/t7_") + if not cover.startswith("http"): + cover = BOOK_ICON_URL 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) @@ -129,13 +123,14 @@ 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 + properties=properties, + cover=utils.get_icon(cover), ) else: - result = notion_helper.create_page( + result = notion_helper.create_book_page( parent=parent, properties=properties, - icon=utils.get_icon(book.get("封面")), + icon=utils.get_icon(cover), ) page_id = result.get("id") if book.get("readDetail") and book.get("readDetail").get("data"): @@ -171,7 +166,11 @@ def insert_to_notion(page_id, timestamp, duration, book_database_id): "标题": utils.get_title( pendulum.from_timestamp(timestamp, tz=tz).to_date_string() ), - "日期": utils.get_date(start=pendulum.from_timestamp(timestamp, tz=tz).format("YYYY-MM-DD HH:mm:ss")), + "日期": utils.get_date( + start=pendulum.from_timestamp(timestamp, tz=tz).format( + "YYYY-MM-DD HH:mm:ss" + ) + ), "时长": utils.get_number(duration), "时间戳": utils.get_number(timestamp), "书架": utils.get_relation([book_database_id]), @@ -206,9 +205,7 @@ def insert_to_notion(page_id, timestamp, duration, book_database_id): or value.get("readingTime") == bookProgress.get(key).get("readingTime") ) and (archive_dict.get(key) == value.get("category")) - and value.get("cover") - and (not value.get("cover").endswith("/0.jpg")) - and (not value.get("cover").endswith("parsecover")) + and (value.get("cover") is not None) and ( value.get("status") != "已读" or (value.get("status") == "已读" and value.get("myRating")) diff --git a/scripts/notion_helper.py b/scripts/notion_helper.py index fdd74193a9db..70b81274c1c6 100644 --- a/scripts/notion_helper.py +++ b/scripts/notion_helper.py @@ -329,14 +329,20 @@ def update_book_page(self, page_id, properties): return self.client.pages.update(page_id=page_id, properties=properties) @retry(stop_max_attempt_number=3, wait_fixed=5000) - def update_page(self, page_id, properties): + def update_page(self, page_id, properties,cover): return self.client.pages.update( - page_id=page_id, properties=properties + page_id=page_id, properties=properties,cover=cover ) @retry(stop_max_attempt_number=3, wait_fixed=5000) def create_page(self, parent, properties, icon): return self.client.pages.create(parent=parent, properties=properties, icon=icon) + + + + @retry(stop_max_attempt_number=3, wait_fixed=5000) + def create_book_page(self, parent, properties, icon): + return self.client.pages.create(parent=parent, properties=properties, icon=icon,cover=icon) @retry(stop_max_attempt_number=3, wait_fixed=5000) def query(self, **kwargs): @@ -381,7 +387,7 @@ def get_all_book(self): "douban_url": get_property_value( result.get("properties").get("豆瓣链接") ), - "cover": get_property_value(result.get("properties").get("封面")), + "cover": result.get("cover"), "myRating": get_property_value( result.get("properties").get("我的评分") ),