Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/easonlee #40

Open
wants to merge 418 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
418 commits
Select commit Hold shift + click to select a range
a5a54db
add new heatmap
actions-user Aug 10, 2024
c182236
add new heatmap
actions-user Aug 10, 2024
dad354b
add new heatmap
actions-user Aug 10, 2024
824df46
add new heatmap
actions-user Aug 10, 2024
8e2c485
add new heatmap
actions-user Aug 11, 2024
0bb590e
add new heatmap
actions-user Aug 11, 2024
660807d
add new heatmap
actions-user Aug 11, 2024
65e722a
add new heatmap
actions-user Aug 11, 2024
7cac6c8
add new heatmap
actions-user Aug 11, 2024
ae1d355
add new heatmap
actions-user Aug 11, 2024
56514c2
add new heatmap
actions-user Aug 11, 2024
f2646da
add new heatmap
actions-user Aug 11, 2024
50a4722
add new heatmap
actions-user Aug 12, 2024
ab0f433
add new heatmap
actions-user Aug 12, 2024
840753e
add new heatmap
actions-user Aug 12, 2024
a6e4fc8
add new heatmap
actions-user Aug 12, 2024
d437fcb
add new heatmap
actions-user Aug 12, 2024
9201d90
add new heatmap
actions-user Aug 12, 2024
2ff9fe1
add new heatmap
actions-user Aug 12, 2024
c6a2e6c
add new heatmap
actions-user Aug 12, 2024
9f8a612
add new heatmap
actions-user Aug 13, 2024
34d9529
add new heatmap
actions-user Aug 13, 2024
ff18c18
add new heatmap
actions-user Aug 13, 2024
badd7eb
add new heatmap
actions-user Aug 13, 2024
e4c90f5
add new heatmap
actions-user Aug 13, 2024
8a99323
add new heatmap
actions-user Aug 13, 2024
8f49a8c
add new heatmap
actions-user Aug 13, 2024
80d5d5f
add new heatmap
actions-user Aug 13, 2024
c926bfc
add new heatmap
actions-user Aug 14, 2024
ceb2f0e
add new heatmap
actions-user Aug 14, 2024
f90586e
add new heatmap
actions-user Aug 14, 2024
fc77bfb
add new heatmap
actions-user Aug 14, 2024
9c4b63d
add new heatmap
actions-user Aug 14, 2024
8c0df0a
add new heatmap
actions-user Aug 14, 2024
df35250
add new heatmap
actions-user Aug 14, 2024
f641edf
add new heatmap
actions-user Aug 14, 2024
45e5995
add new heatmap
actions-user Aug 15, 2024
34dbb65
add new heatmap
actions-user Aug 15, 2024
567904f
add new heatmap
actions-user Aug 15, 2024
9c0ebba
add new heatmap
actions-user Aug 15, 2024
cada92d
add new heatmap
actions-user Aug 15, 2024
f794b0d
add new heatmap
actions-user Aug 15, 2024
ba611f2
add new heatmap
actions-user Aug 15, 2024
95ea811
add new heatmap
actions-user Aug 15, 2024
540ba96
add new heatmap
actions-user Aug 16, 2024
f335c2a
add new heatmap
actions-user Aug 16, 2024
ca57679
add new heatmap
actions-user Aug 16, 2024
711f137
add new heatmap
actions-user Aug 16, 2024
aa89078
add new heatmap
actions-user Aug 16, 2024
5d8f259
add new heatmap
actions-user Aug 16, 2024
025861d
add new heatmap
actions-user Aug 16, 2024
9e16879
add new heatmap
actions-user Aug 16, 2024
1bfaae9
add new heatmap
actions-user Aug 17, 2024
8fd0d24
add new heatmap
actions-user Aug 17, 2024
e5e860b
add new heatmap
actions-user Aug 17, 2024
0799550
add new heatmap
actions-user Aug 17, 2024
7aca874
add new heatmap
actions-user Aug 17, 2024
f48d761
add new heatmap
actions-user Aug 17, 2024
dccd27b
add new heatmap
actions-user Aug 17, 2024
fd6818c
add new heatmap
actions-user Aug 17, 2024
72b5414
add new heatmap
actions-user Aug 18, 2024
75f395e
add new heatmap
actions-user Aug 18, 2024
5605baf
add new heatmap
actions-user Aug 18, 2024
8baa40f
add new heatmap
actions-user Aug 18, 2024
e2ec9de
add new heatmap
actions-user Aug 18, 2024
01389d3
add new heatmap
actions-user Aug 18, 2024
105c520
add new heatmap
actions-user Aug 18, 2024
b307e66
add new heatmap
actions-user Aug 18, 2024
f172da6
add new heatmap
actions-user Aug 19, 2024
7cf6c07
add new heatmap
actions-user Aug 19, 2024
75a01a5
add new heatmap
actions-user Aug 19, 2024
b758a9a
add new heatmap
actions-user Aug 19, 2024
2603304
add new heatmap
actions-user Aug 19, 2024
9b5fa2c
add new heatmap
actions-user Aug 19, 2024
c8c9f93
add new heatmap
actions-user Aug 19, 2024
656e038
add new heatmap
actions-user Aug 19, 2024
128f9e1
add new heatmap
actions-user Aug 20, 2024
bfc0b5c
add new heatmap
actions-user Aug 20, 2024
72169cb
add new heatmap
actions-user Aug 20, 2024
94c7673
add new heatmap
actions-user Aug 20, 2024
2695802
add new heatmap
actions-user Aug 20, 2024
01cd424
add new heatmap
actions-user Aug 20, 2024
35a8834
add new heatmap
actions-user Aug 20, 2024
ac9ab4c
add new heatmap
actions-user Aug 20, 2024
ca7bac1
add new heatmap
actions-user Aug 21, 2024
453b3c3
add new heatmap
actions-user Aug 21, 2024
d24fbab
add new heatmap
actions-user Aug 21, 2024
3c3b84e
add new heatmap
actions-user Aug 21, 2024
08e0565
add new heatmap
actions-user Aug 21, 2024
5822f03
add new heatmap
actions-user Aug 21, 2024
fedbc59
add new heatmap
actions-user Aug 21, 2024
82472ca
add new heatmap
actions-user Aug 21, 2024
4e15bfa
add new heatmap
actions-user Aug 22, 2024
84b4f93
add new heatmap
actions-user Aug 22, 2024
ff7abde
add new heatmap
actions-user Aug 22, 2024
fddf2f0
add new heatmap
actions-user Aug 22, 2024
a64425c
add new heatmap
actions-user Aug 22, 2024
d689c5f
add new heatmap
actions-user Aug 22, 2024
985e4ca
add new heatmap
actions-user Aug 22, 2024
2eca447
add new heatmap
actions-user Aug 22, 2024
8891980
add new heatmap
actions-user Aug 23, 2024
913d4c8
add new heatmap
actions-user Aug 23, 2024
4455739
add new heatmap
actions-user Aug 23, 2024
f324031
add new heatmap
actions-user Aug 23, 2024
1a12ce4
add new heatmap
actions-user Aug 23, 2024
4b8e75f
add new heatmap
actions-user Aug 23, 2024
8cdbc57
add new heatmap
actions-user Aug 23, 2024
baa0490
add new heatmap
actions-user Aug 23, 2024
457a739
add new heatmap
actions-user Aug 24, 2024
f4f838d
add new heatmap
actions-user Aug 24, 2024
e716f1b
add new heatmap
actions-user Aug 24, 2024
0e5490a
add new heatmap
actions-user Aug 24, 2024
b134130
add new heatmap
actions-user Aug 24, 2024
83e431a
add new heatmap
actions-user Aug 24, 2024
5cf8501
add new heatmap
actions-user Aug 24, 2024
41f2bd0
add new heatmap
actions-user Aug 24, 2024
18a554d
add new heatmap
actions-user Aug 25, 2024
b15df52
add new heatmap
actions-user Aug 25, 2024
e72fe72
add new heatmap
actions-user Aug 25, 2024
22930ec
add new heatmap
actions-user Aug 25, 2024
d068f0d
add new heatmap
actions-user Aug 25, 2024
682588c
add new heatmap
actions-user Aug 25, 2024
cb7af8a
add new heatmap
actions-user Aug 25, 2024
890de7b
add new heatmap
actions-user Aug 25, 2024
95669b3
add new heatmap
actions-user Aug 26, 2024
e32bb2e
add new heatmap
actions-user Aug 26, 2024
8bf6ca4
add new heatmap
actions-user Aug 26, 2024
340fa67
add new heatmap
actions-user Aug 26, 2024
d72e4aa
add new heatmap
actions-user Aug 26, 2024
4ecc102
add new heatmap
actions-user Aug 26, 2024
6384f36
add new heatmap
actions-user Aug 26, 2024
f8160ec
add new heatmap
actions-user Aug 26, 2024
3ee7082
add new heatmap
actions-user Aug 27, 2024
a694ad0
add new heatmap
actions-user Aug 27, 2024
d7b7e1b
add new heatmap
actions-user Aug 27, 2024
9ab7979
add new heatmap
actions-user Aug 27, 2024
31092a5
add new heatmap
actions-user Aug 27, 2024
95f3d28
add new heatmap
actions-user Aug 27, 2024
1b6e1c7
add new heatmap
actions-user Aug 27, 2024
4df3b0d
add new heatmap
actions-user Aug 27, 2024
0ccfeba
add new heatmap
actions-user Aug 28, 2024
eb8b19d
add new heatmap
actions-user Aug 28, 2024
336d720
add new heatmap
actions-user Aug 28, 2024
f274ee6
add new heatmap
actions-user Aug 28, 2024
67f4031
add new heatmap
actions-user Aug 28, 2024
55438e1
add new heatmap
actions-user Aug 28, 2024
814b8ea
add new heatmap
actions-user Aug 28, 2024
0c6426a
add new heatmap
actions-user Aug 28, 2024
a8012c5
add new heatmap
actions-user Aug 29, 2024
9afe753
add new heatmap
actions-user Aug 29, 2024
c4c15ff
add new heatmap
actions-user Aug 29, 2024
e5bea5b
add new heatmap
actions-user Aug 29, 2024
686edb1
add new heatmap
actions-user Aug 29, 2024
c5a0b26
add new heatmap
actions-user Aug 29, 2024
0511f22
add new heatmap
actions-user Aug 29, 2024
d766748
add new heatmap
actions-user Aug 29, 2024
e5d1dad
add new heatmap
actions-user Aug 30, 2024
3526bc9
add new heatmap
actions-user Aug 30, 2024
ac7bdbd
add new heatmap
actions-user Aug 30, 2024
ccc8237
add new heatmap
actions-user Aug 30, 2024
1ffca57
add new heatmap
actions-user Aug 30, 2024
01e8c8f
add new heatmap
actions-user Aug 30, 2024
6194e88
add new heatmap
actions-user Aug 30, 2024
c3896ce
add new heatmap
actions-user Aug 30, 2024
c0e1fa4
add new heatmap
actions-user Aug 31, 2024
7a04e6d
add new heatmap
actions-user Aug 31, 2024
36e5198
add new heatmap
actions-user Aug 31, 2024
3abb704
add new heatmap
actions-user Aug 31, 2024
96a3acb
add new heatmap
actions-user Aug 31, 2024
8c24ed9
add new heatmap
actions-user Aug 31, 2024
c2edad6
add new heatmap
actions-user Aug 31, 2024
065a21d
add new heatmap
actions-user Aug 31, 2024
4c53d7e
add new heatmap
actions-user Sep 1, 2024
b47c470
add new heatmap
actions-user Sep 1, 2024
ed34568
add new heatmap
actions-user Sep 1, 2024
b0e98ff
add new heatmap
actions-user Sep 1, 2024
7954c99
add new heatmap
actions-user Sep 1, 2024
c62eb5d
add new heatmap
actions-user Sep 1, 2024
f8097bd
add new heatmap
actions-user Sep 1, 2024
452f88f
add new heatmap
actions-user Sep 1, 2024
498c92b
add new heatmap
actions-user Sep 2, 2024
1021416
add new heatmap
actions-user Sep 2, 2024
e0376a3
add new heatmap
actions-user Sep 2, 2024
08885e4
add new heatmap
actions-user Sep 2, 2024
1dec035
add new heatmap
actions-user Sep 2, 2024
1d803cf
add new heatmap
actions-user Sep 2, 2024
48df80e
add new heatmap
actions-user Sep 2, 2024
ed2a985
add new heatmap
actions-user Sep 2, 2024
a362d03
add new heatmap
actions-user Sep 3, 2024
13ccd15
add new heatmap
actions-user Sep 3, 2024
8c6324d
add new heatmap
actions-user Sep 3, 2024
3e13453
add new heatmap
actions-user Sep 3, 2024
80f1e66
add new heatmap
actions-user Sep 3, 2024
bdb70b8
add new heatmap
actions-user Sep 3, 2024
65ecde8
add new heatmap
actions-user Sep 3, 2024
8c5216b
add new heatmap
actions-user Sep 3, 2024
57bbefe
add new heatmap
actions-user Sep 4, 2024
ff7618f
add new heatmap
actions-user Sep 4, 2024
540d298
add new heatmap
actions-user Sep 4, 2024
60d2c76
add new heatmap
actions-user Sep 4, 2024
082043c
add new heatmap
actions-user Sep 4, 2024
755f924
add new heatmap
actions-user Sep 4, 2024
7cc662e
add new heatmap
actions-user Sep 4, 2024
659d2a7
add new heatmap
actions-user Sep 4, 2024
722593a
add new heatmap
actions-user Sep 5, 2024
684ed64
add new heatmap
actions-user Sep 5, 2024
f872215
add new heatmap
actions-user Sep 5, 2024
c32c9c2
add new heatmap
actions-user Sep 5, 2024
2247ffc
add new heatmap
actions-user Sep 5, 2024
12406ce
add new heatmap
actions-user Sep 5, 2024
dd75d12
add new heatmap
actions-user Sep 5, 2024
00d0549
add new heatmap
actions-user Sep 5, 2024
3af4cda
add new heatmap
actions-user Sep 6, 2024
1ae28a4
add new heatmap
actions-user Sep 6, 2024
f748655
add new heatmap
actions-user Sep 6, 2024
dd8d80d
add new heatmap
actions-user Sep 6, 2024
6dc59ed
add new heatmap
actions-user Sep 6, 2024
d89afa2
add new heatmap
actions-user Sep 6, 2024
fd8bf78
add new heatmap
actions-user Sep 6, 2024
57737ea
add new heatmap
actions-user Sep 6, 2024
0f07692
add new heatmap
actions-user Sep 7, 2024
a86039b
add new heatmap
actions-user Sep 7, 2024
5858233
add new heatmap
actions-user Sep 7, 2024
ba9af51
add new heatmap
actions-user Sep 7, 2024
75efad7
add new heatmap
actions-user Sep 7, 2024
d2b6d2d
add new heatmap
actions-user Sep 7, 2024
7adcc3d
add new heatmap
actions-user Sep 7, 2024
413a20c
add new heatmap
actions-user Sep 7, 2024
f5694e2
add new heatmap
actions-user Sep 8, 2024
9925312
add new heatmap
actions-user Sep 8, 2024
7adf1be
add new heatmap
actions-user Sep 8, 2024
9b3b96a
add new heatmap
actions-user Sep 8, 2024
73cc833
add new heatmap
actions-user Sep 8, 2024
389b166
add new heatmap
actions-user Sep 8, 2024
5ffcbd6
add new heatmap
actions-user Sep 8, 2024
0c28126
add new heatmap
actions-user Sep 8, 2024
9ee5391
add new heatmap
actions-user Sep 9, 2024
acef738
add new heatmap
actions-user Sep 9, 2024
7dd7573
add new heatmap
actions-user Sep 9, 2024
67d0af3
add new heatmap
actions-user Sep 9, 2024
4103da3
add new heatmap
actions-user Sep 9, 2024
d753f83
add new heatmap
actions-user Sep 9, 2024
dbc9ec9
add new heatmap
actions-user Sep 9, 2024
59636a4
add new heatmap
actions-user Sep 9, 2024
642f308
add new heatmap
actions-user Sep 10, 2024
ca9701d
add new heatmap
actions-user Sep 10, 2024
1f38273
add new heatmap
actions-user Sep 10, 2024
a061de6
add new heatmap
actions-user Sep 10, 2024
046e4e0
add new heatmap
actions-user Sep 18, 2024
73b4390
适配life os 1.1
Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/weread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: weread note sync
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
- cron: "0 * * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -33,6 +33,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: dev/easonlee
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -47,4 +49,4 @@ jobs:
- name: weread sync
run: |
python -u scripts/weread.py


2 changes: 2 additions & 0 deletions OUT_FOLDER/7d4e80c3-3325-43e5-a3d0-66461f739274.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

| 微信群 | QQ群 |
| --- | --- |
| <div align="center"><img src="https://github.com/malinkang/weread2notion/assets/3365208/e28d1fb8-a861-47e1-b5e8-b25f17a6a285" ></div> | <div align="center"><img src="https://images.malinkang.com/2024/04/b225b17d60670e4a6ff3459bbde80d28.jpg" width="50%"></div> |
| <div align="center"><img src="https://images.malinkang.com/2024/04/2dba3fdad0dbe53663c4de076b36baed.jpg" ></div> | <div align="center"><img src="https://images.malinkang.com/2024/04/b225b17d60670e4a6ff3459bbde80d28.jpg" width="50%"></div> |


## 捐赠
Expand Down
110 changes: 84 additions & 26 deletions scripts/book.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import traceback
from datetime import datetime, timedelta
import os

Expand All @@ -10,6 +11,8 @@
import utils
from config import book_properties_type_dict, tz
from retrying import retry
import json
from datetime import datetime

TAG_ICON_URL = "https://www.notion.so/icons/tag_gray.svg"
USER_ICON_URL = "https://www.notion.so/icons/user-circle-filled_gray.svg"
Expand Down Expand Up @@ -48,6 +51,7 @@ def insert_book_to_notion(books, index, bookId):
book["书架分类"] = archive_dict.get(bookId)
if bookId in notion_books:
book.update(notion_books.get(bookId))

bookInfo = weread_api.get_bookinfo(bookId)
if bookInfo != None:
book.update(bookInfo)
Expand All @@ -62,13 +66,13 @@ def insert_book_to_notion(books, index, bookId):
markedStatus = book.get("markedStatus")
status = "想读"
if markedStatus == 4:
status = "已读"
status = "阅读完"
elif book.get("readingTime", 0) >= 60:
status = "在读"
book["阅读状态"] = status
book["阅读时长"] = book.get("readingTime")
book["阅读天数"] = book.get("totalReadDay")
book["评分"] = book.get("newRating")
#book["评分"] = book.get("newRating")
if book.get("newRatingDetail") and book.get("newRatingDetail").get("myRating"):
book["我的评分"] = rating.get(book.get("newRatingDetail").get("myRating"))
elif status == "已读":
Expand All @@ -81,43 +85,53 @@ def insert_book_to_notion(books, index, bookId):
elif book.get("readingBookDate"):
date = book.get("readingBookDate")
book["时间"] = date
book["开始阅读时间"] = book.get("beginReadingDate")
book["最后阅读时间"] = book.get("lastReadingDate")
book["类型"] = "书籍"
#book["开始阅读时间"] = book.get("beginReadingDate")
#book["最后阅读时间"] = book.get("lastReadingDate")
cover = book.get("cover").replace("/s_", "/t7_")
if not cover and not cover.strip() and not cover.startswith("http"):
cover = BOOK_ICON_URL
if bookId not in notion_books:
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")
#链接timeout,先注释
#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")
book["链接"] = utils.get_weread_url(bookId)
book["简介"] = book.get("intro")
#book["简介"] = book.get("intro")
book["作者"] = [
notion_helper.get_relation_id(
x, notion_helper.author_database_id, USER_ICON_URL
)
for x in book.get("author").split(" ")
]
if book.get("categories"):
book["分类"] = [
notion_helper.get_relation_id(
x.get("title"), notion_helper.category_database_id, TAG_ICON_URL
)
for x in book.get("categories")
]
#if book.get("categories"):
# book["分类"] = [
# notion_helper.get_relation_id(
# x.get("title"), notion_helper.category_database_id, TAG_ICON_URL
# )
# for x in book.get("categories")
# ]
properties = utils.get_properties(book, book_properties_type_dict)

#print(f"正在插入《{book.get('title')}》,一共{len(books)}本,当前是第{index+1}本。")
if not book.get("readDetail") or not book.get("readDetail").get("data"):
print(f"《{book.get('title')}》没有阅读记录,跳过")
return

if book.get("时间"):
notion_helper.get_date_relation(
#取书籍的阅读记录,可能有多天
book['时间'] = [x['readDate'] for x in book.get('readDetail').get('data')]
notion_helper.get_date_relations(
properties,
pendulum.from_timestamp(book.get("时间"), tz="Asia/Shanghai"),
#时间戳转换为北京时间
[pendulum.from_timestamp(x, tz="Asia/Shanghai") for x in book.get("时间")]
)

print(f"正在插入《{book.get('title')}》,一共{len(books)}本,当前是第{index+1}本。")
parent = {"database_id": notion_helper.book_database_id, "type": "database_id"}
result = None
if bookId in notion_books:
Expand All @@ -142,6 +156,7 @@ def insert_book_to_notion(books, index, bookId):
def insert_read_data(page_id, readTimes):
readTimes = dict(sorted(readTimes.items()))
filter = {"property": "书架", "relation": {"contains": page_id}}
#拿到当前书籍$page_id的所有阅读记录
results = notion_helper.query_all_by_book(notion_helper.read_database_id, filter)
for result in results:
timestamp = result.get("properties").get("时间戳").get("number")
Expand All @@ -160,6 +175,7 @@ def insert_read_data(page_id, readTimes):
insert_to_notion(None, int(key), value, page_id)


#插入或更新阅读记录
def insert_to_notion(page_id, timestamp, duration, book_database_id):
parent = {"database_id": notion_helper.read_database_id, "type": "database_id"}
properties = {
Expand All @@ -186,36 +202,78 @@ def insert_to_notion(page_id, timestamp, duration, book_database_id):


if __name__ == "__main__":
current_time = datetime.now()
print("开始同步阅读记录,当前时间: ", current_time)
weread_api = WeReadApi()
notion_helper = NotionHelper()
notion_books = notion_helper.get_all_book()
bookshelf_books = weread_api.get_bookshelf()
# 有阅读记录的图书信息
# 样例数据:{'$bookId': {'bookId': '26062915', 'progress': 1, 'chapterUid': 8, 'chapterOffset': 0,
# 'chapterIdx': 8, 'appId': '11413501', 'updateTime': 1691221509, 'readingTime': 875,
# 'syncKey': 720606794}
# }
bookProgress = bookshelf_books.get("bookProgress")
bookProgress = {book.get("bookId"): book for book in bookProgress}
archive_dict = {}
#acchive是书单的名字
for archive in bookshelf_books.get("archive"):
name = archive.get("name")
bookIds = archive.get("bookIds")
archive_dict.update({bookId: name for bookId in bookIds})
not_need_sync = []
# Notion里的文献笔记
# 样例数据:{'$bookId': {'pageId': '10c911dc-da56-8106-8b58-ddaacc287c74', 'readingTime': 2325,
# 'category': None, 'Sort': None, 'douban_url': None,
# 'cover': {'type': 'external', 'external': {'url': 'https://bts-image.xyzcdn.net/aHR0cHM6Ly9pbWFnZS54eXpjZG4ubmV0L0ZxUWs2VThtWDU0YnZ3MFBsbm5HemtHMVpEajkuanBn.jpg'}},
# 'myRating': None, 'comment': None, 'status': '阅读完'}
# }
for key, value in notion_books.items():
if (
(
key not in bookProgress
or value.get("readingTime") == bookProgress.get(key).get("readingTime")
)
and (archive_dict.get(key) == value.get("category"))
and (value.get("cover") is not None)
and (
value.get("status") != "已读"
or (value.get("status") == "已读" and value.get("myRating"))
)
#and (value.get("cover") is not None)
#and (
# value.get("status") != "已读"
# or (value.get("status") == "已读" and value.get("myRating"))
#)
):
#这里判定Notion中的书籍和微信中的书籍是否有属性发现变化,没有的话就不需要同步了
not_need_sync.append(key)
#continue
notebooks = weread_api.get_notebooklist()
notebooks_map = {d["bookId"] : d for d in notebooks if "bookId" in d}
notebooks = [d["bookId"] for d in notebooks if "bookId" in d]

books = bookshelf_books.get("books")
bookshelf_map = {d["bookId"] : d for d in books if "bookId" in d}
books = [d["bookId"] for d in books if "bookId" in d]


books = list((set(notebooks) | set(books)) - set(not_need_sync))
len = len(books)
for index, bookId in enumerate(books):
insert_book_to_notion(books, index, bookId)
try:
bp = bookProgress[bookId] if bookId in bookProgress else None
bs = bookshelf_map[bookId] if bookId in bookshelf_map else None
nt = notebooks_map[bookId] if bookId in notebooks_map else None

title = bs['title'] if bs and 'title' in bs else ""
print(f"正在插入《{title}》,一共{len}本,当前是第{index + 1}本。")

if bp and bp['readingTime'] < 600:
print(f"《{title}》阅读不超时10分钟,跳过")
continue

if not nt:
print(f"《{title}》没有阅读笔记,跳过")
continue

insert_book_to_notion(books, index, bookId)
except Exception as e:
print("处理book: " + bookId + "出现异常,跳过:")
traceback.print_exc()
continue
3 changes: 2 additions & 1 deletion scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SELECT = "select"

book_properties_type_dict = {
"书名":TITLE,
"标题":TITLE,
"BookId":RICH_TEXT,
"ISBN":RICH_TEXT,
"链接":URL,
Expand All @@ -30,5 +30,6 @@
"书架分类":SELECT,
"我的评分":SELECT,
"豆瓣链接":URL,
"类型":SELECT
}
tz='Asia/Shanghai'
Loading