Skip to content

Commit

Permalink
fix cover
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Apr 19, 2024
1 parent 49cab35 commit 9c9b8b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
29 changes: 13 additions & 16 deletions scripts/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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"))
Expand Down
12 changes: 9 additions & 3 deletions scripts/notion_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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("我的评分")
),
Expand Down

0 comments on commit 9c9b8b4

Please sign in to comment.