Skip to content

Commit

Permalink
添加我的评分
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Jan 25, 2024
1 parent 1bc6635 commit e36eea5
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 132 deletions.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ requests
notion-client
github-heatmap
retrying
pendulum
beautifulsoup4
pendulum
Binary file modified scripts/__pycache__/config.cpython-311.pyc
Binary file not shown.
Binary file modified scripts/__pycache__/notion_helper.cpython-311.pyc
Binary file not shown.
Binary file modified scripts/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file modified scripts/__pycache__/weread_api.cpython-311.pyc
Binary file not shown.
55 changes: 35 additions & 20 deletions scripts/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
from weread_api import WeReadApi
import utils
from config import (
book_properties_name_dict,
book_properties_type_dict,
)
from bs4 import BeautifulSoup
from retrying import retry

TAG_ICON_URL = "https://www.notion.so/icons/tag_gray.svg"
USER_ICON_URL = "https://www.notion.so/icons/user-circle-filled_gray.svg"
BOOK_ICON_URL = "https://www.notion.so/icons/book_gray.svg"

rating = {"poor": "⭐️", "fair": "⭐️⭐️⭐️", "good": "⭐️⭐️⭐️⭐️⭐️"}


@retry(stop_max_attempt_number=3, wait_fixed=5000)
def get_douban_url(isbn):
print(f"get_douban_url {isbn} ")
Expand All @@ -42,11 +43,12 @@ def get_douban_url(isbn):
return None
return urls[0].get("url")


def insert_book_to_notion(books, index, bookId):
"""插入Book到Notion"""
book = {}
if bookId in archive_dict:
book["archive"] = archive_dict.get(bookId)
book["书架分类"] = archive_dict.get(bookId)
if bookId in notion_books:
book.update(notion_books.get(bookId))
bookInfo = weread_api.get_bookinfo(bookId)
Expand All @@ -70,51 +72,60 @@ def insert_book_to_notion(books, index, bookId):
douban_url = get_douban_url(isbn)
if douban_url:
book["douban_url"] = douban_url
book["cover"] = cover
book["readingProgress"] = (
book["封面"] = cover
book["阅读进度"] = (
100 if (book.get("markedStatus") == 4) else book.get("readingProgress", 0)
) / 100
markedStatus = book.get("markedStatus")
markedStatus = book.get("markedStatus")
status = "想读"
if(markedStatus==4):
if markedStatus == 4:
status = "已读"
elif(book.get("readingTime",0)>=60):
elif book.get("readingTime", 0) >= 60:
status = "在读"
book["status"] = status
book["阅读状态"] = status
book["阅读时长"] = book.get("readingTime")
book["阅读天数"] = book.get("totalReadDay")
book["评分"] = book.get("newRating")
if book.get("newRatingDetail") and book.get("newRatingDetail").get("myRating"):
book["我的评分"] = rating.get(book.get("newRatingDetail").get("myRating"))
elif status=="已读":
book["我的评分"] = "未评分"
date = None
if book.get("finishedDate"):
date = book.get("finishedDate")
elif book.get("lastReadingDate"):
date = book.get("lastReadingDate")
elif book.get("readingBookDate"):
date = book.get("readingBookDate")
book["date"] = date
book["时间"] = date
book["开始阅读时间"] = book.get("beginReadingDate")
book["最后阅读时间"] = book.get("lastReadingDate")
if bookId not in notion_books:
book["author"] = [
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["作者"] = [
notion_helper.get_relation_id(
x, notion_helper.author_database_id, USER_ICON_URL
)
for x in book.get("author").split(" ")
]
book["url"] = utils.get_weread_url(bookId)
if book.get("categories"):
book["categories"] = [
book["分类"] = [
notion_helper.get_relation_id(
x.get("title"), notion_helper.category_database_id, TAG_ICON_URL
)
for x in book.get("categories")
]
else:
book.pop("categories",None)
book.pop("author",None)
properties = utils.get_properties(
book, book_properties_name_dict, book_properties_type_dict
)
]
properties = utils.get_properties(book, book_properties_type_dict)
if book.get("date"):
notion_helper.get_date_relation(
properties,
pendulum.from_timestamp(book.get("date"), tz="Asia/Shanghai"),
)

print(f"正在插入《{book.get('title')}》,一共{len(books)}本,当前是第{index+1}本。")
parent = {"database_id": notion_helper.book_database_id, "type": "database_id"}
if bookId in notion_books:
Expand Down Expand Up @@ -159,6 +170,10 @@ def insert_book_to_notion(books, index, bookId):
and value.get("cover")
and (not value.get("cover").endswith("/0.jpg"))
and (not value.get("cover").endswith("parsecover"))
and (
value.get("status") != "已读"
or (value.get("status") == "已读" and value.get("myRating"))
)
):
not_need_sync.append(key)
notebooks = weread_api.get_notebooklist()
Expand Down
25 changes: 1 addition & 24 deletions scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,6 @@
TITLE = "title"
SELECT = "select"

book_properties_name_dict = {
"title":"书名",
"bookId":"BookId",
"isbn":"ISBN",
"url":"链接",
"author":"作者",
"Sort":"Sort",
"newRating":"评分",
"cover":"封面",
"categories":"分类",
"status":"阅读状态",
"readingTime":"阅读时长",
"readingProgress":"阅读进度",
"totalReadDay":"阅读天数",
"date":"时间",
"beginReadingDate":"开始阅读时间",
"lastReadingDate":"最后阅读时间",
"intro":"简介",
"archive":"书架分类",
"douban_url":"豆瓣链接",
"neodb_url":"NeoDB链接",
}

book_properties_type_dict = {
"书名":TITLE,
"BookId":RICH_TEXT,
Expand All @@ -51,6 +28,6 @@
"最后阅读时间":DATE,
"简介":RICH_TEXT,
"书架分类":SELECT,
"我的评分":SELECT,
"豆瓣链接":URL,
"NeoDB链接":URL,
}
Loading

0 comments on commit e36eea5

Please sign in to comment.