Code Monkey home page Code Monkey logo

notion-douban-sync's Introduction

Notion-Douban Sync

用来把 Notion 数据库的书籍、电影评价同步到豆瓣。

由于豆瓣无法支持修改评价日期以及记录多次评价,本工具把 Notion 数据库中的重复项的评价按日期倒序合并,作为在豆瓣的“短评”,并用最近一次的评价作为豆瓣评价。

用法

准备环境

git clone https://github.com/stdrc/notion-douban-sync.git
cd notion-douban-sync

# 安装 Node 依赖
npm install

# 安装 Python 依赖
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

准备 Notion API 和豆瓣 Cookie

先摆了,可以网上搜索如何获得。获得后,拷贝 .env.example.env,填入到对应项。

从 Notion 数据库获取评价数据

node get_notion_reviews.js movie <database_id>

这里 movie 可以改成 book。脚本假设数据库 schema 和 我的 一致,如果不一致,可以自行修改脚本或者用其它方式导出为兼容的 JSON 文件。

JSON 文件形如:

[
    {
        "name": "死亡诗社",
        "douban_url": "https://movie.douban.com/subject/1291548/",
        "rating_date": "2023-07-23",
        "rating": "👍 值得一看",
        "rating_score": 1,
        "public_url": "https://stdrc.notion.site/1d7942b7347546fe928ed38131b6b6c7"
    }
]

其中 rating 可以是任何字符串,后面的脚本是依据 rating_score 在豆瓣评分;rating_score 采用 -2 到 +2 的评价方式,-2 表示极差,-1 表示较差,0 表示无感,1 表示较好,2 表示极好;public_url 是可以公开访问的影评/书评链接,目前没用到,可以留空。

同步评价到豆瓣

python3 sync_to_douban.py --dry-run movie

注意这里加了 --dry-run 表示只打印到控制台,不真的请求豆瓣 API,去掉会真的往豆瓣同步。可以通过 python sync_to_douban.py --help 查看更多用法,比如限制只同步一定时间范围内的数据:

python3 sync_to_douban.py \
    --dry-run \
    --start-date 2022-01-01 \
    --end-date 2022-12-31 \
    movie

如果只需要同步今天刚评价的内容:

python3 sync_to_douban.py \
    --dry-run \
    --start-date today \
    movie

notion-douban-sync's People

Contributors

stdrc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.