Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Nov 14, 2024
1 parent daa7d93 commit 02c758e
Show file tree
Hide file tree
Showing 33 changed files with 1,221 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/douban_book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
pip install -r requirements.txt
- name: douban book sync
run: |
python -u scripts/douban.py "book"
douban "book"
- name: Remove folder
run: rm -rf ./OUT_FOLDER/book
- name: Set default year if not provided
Expand All @@ -44,7 +44,7 @@ jobs:
github_heatmap notion --notion_token "${{ secrets.BOOK_NOTION_TOKEN || secrets.NOTION_TOKEN }}" --database_id "${{ env.DATABASE_ID }}" --date_prop_name "日期" --value_prop_name "读过" --unit "本" --year $YEAR --me "${{secrets.BOOK_NAME}}" --without-type-name --background-color=${{ vars.background_color||'#FFFFFF'}} --track-color=${{ vars.track_color||'#ACE7AE'}} --special-color1=${{ vars.special_color||'#69C16E'}} --special-color2=${{ vars.special_color2||'#549F57'}} --dom-color=${{ vars.dom_color||'#EBEDF0'}} --text-color=${{ vars.text_color||'#000000'}}
- name: udpate heatmap
run: |
python -u scripts/update_heatmap.py "book"
heatmap "book"
- name: push
run: |
git config --local user.email "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/douban_movie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
pip install -r requirements.txt
- name: douban movie sync
run: |
python -u scripts/douban.py "movie"
douban "movie"
- name: Remove folder
run: rm -rf ./OUT_FOLDER/movie
- name: Set default year if not provided
Expand All @@ -44,7 +44,7 @@ jobs:
github_heatmap notion --notion_token "${{secrets.MOVIE_NOTION_TOKEN || secrets.NOTION_TOKEN}}" --database_id "${{ env.DATABASE_ID }}" --date_prop_name "日期" --value_prop_name "看过" --unit "部" --year $YEAR --me "${{secrets.MOVIE_NAME}}" --without-type-name --background-color=${{ vars.background_color||'#FFFFFF'}} --track-color=${{ vars.track_color||'#ACE7AE'}} --special-color1=${{ vars.special_color||'#69C16E'}} --special-color2=${{ vars.special_color2||'#549F57'}} --dom-color=${{ vars.dom_color||'#EBEDF0'}} --text-color=${{ vars.text_color||'#000000'}}
- name: udpate heatmap
run: |
python -u scripts/update_heatmap.py "movie"
heatmap.py "movie"
- name: push
run: |
git config --local user.email "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
scripts/__pycache__/
douban2notion/__pycache__/
.env
a
Empty file.
4 changes: 4 additions & 0 deletions build/lib/douban2notion/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from book import main

if __name__ == "__main__":
main()
File renamed without changes.
56 changes: 22 additions & 34 deletions scripts/douban.py → build/lib/douban2notion/douban.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import argparse
from email import feedparser
import json
import os
import re
import pendulum
from retrying import retry
import requests
from notion_helper import NotionHelper
import utils
import feedparser

from douban2notion.notion_helper import NotionHelper
from douban2notion import utils
DOUBAN_API_HOST = os.getenv("DOUBAN_API_HOST", "frodo.douban.com")
DOUBAN_API_KEY = os.getenv("DOUBAN_API_KEY", "0ac44ae016490db2204ce0a042db2916")

from config import movie_properties_type_dict,book_properties_type_dict, TAG_ICON_URL, USER_ICON_URL
from utils import get_icon
from douban2notion.config import movie_properties_type_dict,book_properties_type_dict, TAG_ICON_URL, USER_ICON_URL
from douban2notion.utils import get_icon
from dotenv import load_dotenv
load_dotenv()
rating = {
Expand Down Expand Up @@ -41,7 +40,6 @@
"user-agent": "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.16(0x18001023) NetType/WIFI Language/zh_CN",
"referer": "https://servicewechat.com/wx2f9b06c1de1ccfca/84/page-frame.html",
}

@retry(stop_max_attempt_number=3, wait_fixed=5000)
def fetch_subjects(user, type_, status):
offset = 0
Expand Down Expand Up @@ -73,7 +71,7 @@ def fetch_subjects(user, type_, status):



def insert_movie():
def insert_movie(douban_name,notion_helper):
notion_movies = notion_helper.query_all(database_id=notion_helper.movie_database_id)
notion_movie_dict = {}
for i in notion_movies:
Expand All @@ -93,11 +91,11 @@ def insert_movie():
results.extend(fetch_subjects(douban_name, "movie", i))
for result in results:
movie = {}
if not result:
print(result)
continue
subject = result.get("subject")
if(subject.get("title")=="未知电影" or subject.get("title")=="未知电视剧") and subject.get("url") in unknown_dict:
unknown = unknown_dict.get(subject.get("url"))
subject["title"] = unknown.get("title")
subject["pic"]["large"] = unknown.get("img")
print(f"title = {subject.get('title')}")
movie["电影名"] = subject.get("title")
create_time = result.get("create_time")
create_time = pendulum.parse(create_time,tz=utils.tz)
Expand Down Expand Up @@ -127,7 +125,9 @@ def insert_movie():

else:
print(f"插入{movie.get('电影名')}")
cover = subject.get("pic").get("large")
cover = subject.get("pic").get("normal")
if not cover.endswith('.webp'):
cover = cover.rsplit('.', 1)[0] + '.webp'
movie["封面"] = cover
movie["类型"] = subject.get("type")
if subject.get("genres"):
Expand Down Expand Up @@ -165,7 +165,7 @@ def insert_movie():
)


def insert_book():
def insert_book(douban_name,notion_helper):
notion_books = notion_helper.query_all(database_id=notion_helper.book_database_id)
notion_book_dict = {}
for i in notion_books:
Expand Down Expand Up @@ -247,31 +247,19 @@ def insert_book():
parent=parent, properties=properties, icon=get_icon(cover)
)

def parse_interests():
items = feedparser.parse(f'https://www.douban.com/feed/people/{douban_name}/interests')
pattern = r'<img [^>]*src="([^"]+)"'
for item in items.get("entries"):
match = re.search(pattern, item.get("summary"))
if match:
img_url = match.group(1)
unknown_dict[item.get("link").replace("http:","https:")]={
"title": item.get("title")[2:],
"img": img_url,
}
else:
print("没有找到图片链接")

unknown_dict = {}
if __name__ == "__main__":

def main():
parser = argparse.ArgumentParser()
parser.add_argument("type")
options = parser.parse_args()
type = options.type
is_movie = True if type=="movie" else False
print(f"type= {type}")
notion_helper = NotionHelper(type)
is_movie = True if type=="movie" else False
douban_name = os.getenv("DOUBAN_NAME", None)
parse_interests()
if is_movie:
insert_movie()
insert_movie(douban_name,notion_helper)
else:
insert_book()
insert_book(douban_name,notion_helper)
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging
import os
import re
import time

from notion_client import Client
from retrying import retry
from datetime import timedelta

from utils import (
from douban2notion.utils import (
format_date,
get_date,
get_first_and_last_day_of_month,
Expand All @@ -18,8 +16,6 @@
get_relation,
get_rich_text,
get_title,
timestamp_to_date,
get_property_value,
)

TAG_ICON_URL = "https://www.notion.so/icons/tag_gray.svg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import shutil
import time
from notion_helper import NotionHelper
from douban2notion.notion_helper import NotionHelper

def move_and_rename_file(type):

Expand All @@ -21,7 +21,8 @@ def move_and_rename_file(type):
shutil.move(source_path, target_path)
# 返回移动后的文件路径
return target_path
if __name__ == "__main__":

def main():
parser = argparse.ArgumentParser()
parser.add_argument("type")
options = parser.parse_args()
Expand All @@ -34,4 +35,6 @@ def move_and_rename_file(type):
if notion_helper.heatmap_block_id:
response = notion_helper.update_heatmap(
block_id=notion_helper.heatmap_block_id, url=heatmap_url
)
)
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion scripts/utils.py → build/lib/douban2notion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import requests
import base64
from config import (
from douban2notion.config import (
RICH_TEXT,
URL,
RELATION,
Expand Down
Binary file added dist/douban2notion-0.0.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/douban2notion-0.0.2.tar.gz
Binary file not shown.
Binary file added dist/douban2notion-0.0.3-py3-none-any.whl
Binary file not shown.
Binary file added dist/douban2notion-0.0.3.tar.gz
Binary file not shown.
59 changes: 59 additions & 0 deletions douban2notion.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Metadata-Version: 2.1
Name: douban2notion
Version: 0.0.3
Summary: 自动将豆瓣电影和豆瓣读书同步到Notion
Home-page: https://github.com/malinkang/weread2notion-pro
Author: malinkang
Author-email: [email protected]
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: pendulum
Requires-Dist: retrying
Requires-Dist: notion-client
Requires-Dist: github-heatmap
Requires-Dist: python-dotenv

# 将豆瓣电影和读书同步到Notion


本项目通过Github Action每天定时同步豆瓣电影和读书到Notion。

* 豆瓣电影预览效果:https://douban-movie.malinkang.com/
* 豆瓣图书预览效果:https://douban-book.malinkang.com/


## 使用

> [!IMPORTANT]
> 关注公众号回复豆瓣获取教程,后续有更新也会第一时间在公众号里同步。

![扫码_搜索联合传播样式-标准色版](https://github.com/malinkang/weread2notion/assets/3365208/191900c6-958e-4f9b-908d-a40a54889b5e)


## 群
> [!IMPORTANT]
> 欢迎加入群讨论。可以讨论使用中遇到的任何问题,也可以讨论Notion使用,后续我也会在群中分享更多Notion自动化工具。微信群失效的话可以添加我的微信malinkang,我拉你入群。

| 微信群 | QQ群 |
| --- | --- |
| <div align="center"><img src="https://github.com/malinkang/Podcast2Notion/assets/3365208/f38804e6-fe05-4754-9188-122a08e43fec" ></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/03/7fd0feb1145f19fab3821ff1d4631f85.jpg" width="50%"></div> | <div align="center"><img src="https://images.malinkang.com/2024/03/d34f577490a32d4440c8a22f57af41da.jpg" width="50%"></div> |

## 其他项目
* [WeRead2Notion-Pro](https://github.com/malinkang/weread2notion-pro)
* [WeRead2Notion](https://github.com/malinkang/weread2notion)
* [Podcast2Notion](https://github.com/malinkang/podcast2notion)
* [Douban2Notion](https://github.com/malinkang/douban2notion)
* [Keep2Notion](https://github.com/malinkang/keep2notion)
15 changes: 15 additions & 0 deletions douban2notion.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
README.md
setup.py
douban2notion/__init__.py
douban2notion/__main__.py
douban2notion/config.py
douban2notion/douban.py
douban2notion/notion_helper.py
douban2notion/update_heatmap.py
douban2notion/utils.py
douban2notion.egg-info/PKG-INFO
douban2notion.egg-info/SOURCES.txt
douban2notion.egg-info/dependency_links.txt
douban2notion.egg-info/entry_points.txt
douban2notion.egg-info/requires.txt
douban2notion.egg-info/top_level.txt
1 change: 1 addition & 0 deletions douban2notion.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions douban2notion.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[console_scripts]
douban = douban2notion.douban:main
heatmap = douban2notion.upadte_heatmap:main
6 changes: 6 additions & 0 deletions douban2notion.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requests
pendulum
retrying
notion-client
github-heatmap
python-dotenv
1 change: 1 addition & 0 deletions douban2notion.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
douban2notion
Empty file added douban2notion/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions douban2notion/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from book import main

if __name__ == "__main__":
main()
58 changes: 58 additions & 0 deletions douban2notion/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

RICH_TEXT = "rich_text"
URL = "url"
RELATION = "relation"
NUMBER = "number"
DATE = "date"
FILES = "files"
STATUS = "status"
TITLE = "title"
SELECT = "select"
MULTI_SELECT = "multi_select"

book_properties_type_dict = {
"书名":TITLE,
"短评":RICH_TEXT,
"ISBN":RICH_TEXT,
"豆瓣链接":URL,
"作者":RELATION,
"评分":SELECT,
"封面":FILES,
"分类":RELATION,
"状态":STATUS,
"日期":DATE,
"简介":RICH_TEXT,
"豆瓣链接":URL,
"出版社":MULTI_SELECT,
}

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"


movie_properties_type_dict = {
"电影名":TITLE,
"短评":RICH_TEXT,
# "ISBN":RICH_TEXT,
# "链接":URL,
"导演":RELATION,
"演员":MULTI_SELECT,
# "Sort":NUMBER,
"封面":FILES,
"分类":RELATION,
"状态":STATUS,
"类型":SELECT,
"评分":SELECT,
# "阅读时长":NUMBER,
# "阅读进度":NUMBER,
# "阅读天数":NUMBER,
"日期":DATE,
"简介":RICH_TEXT,
# "开始阅读时间":DATE,
# "最后阅读时间":DATE,
# "简介":RICH_TEXT,
# "书架分类":SELECT,
# "我的评分":SELECT,
"豆瓣链接":URL,
}
Loading

0 comments on commit 02c758e

Please sign in to comment.