Skip to content

Commit 6e7060d

Browse files
committed
add categories
1 parent 4163a2b commit 6e7060d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

weread.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def get_chapter_info(bookId):
197197
return None
198198

199199

200-
def insert_to_notion(bookName, bookId, cover, sort, author,isbn,rating):
200+
def insert_to_notion(bookName, bookId, cover, sort, author,isbn,rating,categories):
201201
"""插入到notion"""
202202
time.sleep(0.3)
203203
parent = {
@@ -214,12 +214,14 @@ def insert_to_notion(bookName, bookId, cover, sort, author,isbn,rating):
214214
"Rating": {"number": rating},
215215
"Cover": {"files": [{"type": "external", "name": "Cover", "external": {"url": cover}}]},
216216
}
217+
if(categories!=None):
218+
multi_select = [{"name": x} for x in categories]
219+
properties["Categories"] = {"multi_select":multi_select}
217220
read_info = get_read_info(bookId=bookId)
218221
if read_info != None:
219222
markedStatus = read_info.get("markedStatus", 0)
220223
readingTime = read_info.get("readingTime", 0)
221224
readingProgress = read_info.get("readingProgress", 0)
222-
print(f"readingProgress = {readingProgress}")
223225
format_time = ""
224226
hour = readingTime // 3600
225227
if hour > 0:
@@ -416,10 +418,13 @@ def calculate_book_str_id(book_id):
416418
cover += ".jpg"
417419
bookId = book.get("bookId")
418420
author = book.get("author")
421+
categories = book.get("categories")
422+
if(categories!=None):
423+
categories = [x["title"] for x in categories]
419424
print(f"正在同步 {title} ,一共{len(books)}本,当前是第{i}本。")
420425
check(bookId)
421426
isbn,rating = get_bookinfo(bookId)
422-
id = insert_to_notion(title, bookId, cover, sort, author,isbn,rating)
427+
id = insert_to_notion(title, bookId, cover, sort, author,isbn,rating,categories)
423428
chapter = get_chapter_info(bookId)
424429
bookmark_list = get_bookmark_list(bookId)
425430
summary, reviews = get_review_list(bookId)

0 commit comments

Comments
 (0)