How petter-gao/weread2notion works
Project type and purpose
• This is a small automation tool (not a full‑stack app) whose sole purpose is to “每天定时同步微信读书划线到 Notion” by running a Python script in GitHub Actions.
File structure
• Top‐level
• .github/workflows/weread.yml – the CI/CD workflow that schedules and runs the sync
• weread.py – the entry point CLI or main script
• requirements.txt – declares Python dependencies (e.g., requests, notion‑client)
• OUT_FOLDER – local output/cache of fetched highlights (intermediate storage)
• scripts/
– utils.py – helper functions (HTTP clients, parsing, etc.)
– weread.py – core logic for fetching from WeRead and pushing to Notion
• No frontend; purely backend automation.
README for additional insights
• Scheduled via GitHub Action (daily)
• Uses WeRead API (via cookies or session) to fetch user highlights/notes
• Uses Notion API to upsert pages under a given Notion database
• Environment variables/secrets drive credentials
a. Main components
1. GitHub Actions Scheduler
2. GitHub Runner (Ubuntu VM)
3. Python Script (weread.py + scripts module)
4. WeRead Service (external HTTP API)
5. Notion Service (external HTTP API)
6. Local Storage (OUT_FOLDER)
b. Relationships / Data flow
1. Scheduler → triggers → Runner
2. Runner → checks out repo → installs dependencies
3. Runner → invokes → Python CLI (weread.py)
4. Python CLI → loads utils + scripts/weread to:
• authenticate & fetch highlights from WeRead API
• compare/store interim results in OUT_FOLDER
• authenticate & push updates to Notion API
5. Notion API → returns status → script logs to Runner console
c. Architectural patterns & principles
• Single responsibility: weread.py is the entrypoint; scripts/weread.py does core sync logic; utils.py holds shared helpers.
• CI/CD as scheduler: using GitHub Actions workflow as a timed cron job.
• Idempotent sync: storing state in OUT_FOLDER to avoid re‑posting duplicates.
d. Key technologies
• GitHub Actions (YAML workflow)
• Python 3.x, pip
• requests or httpx (for REST calls)
• notion‑client or direct REST
• WeRead HTTP endpoints (cookie/session based)