GithubHelp home page GithubHelp logo

mcnamee / bear-app-to-notion Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyunhwan-jeong/bear-app-to-notion

0.0 1.0 0.0 532 KB

This repository shows how to import bear app documents to notion

Python 100.00%

bear-app-to-notion's Introduction

bear-app-to-notion

This repository introduces how to import documents in bear app to notion. The current notion import tool is limited because it can't import images. I did some research and wrote a script to import the bear app documents properly. The method has been tested in macOS with Python 3.8.3.

Export bear notebook

First, it requires to export documents from bear app. It is possible to select to specific documents or a tag to export. The export format has to be markdown, and Export attachments option has to be ON.

Bear Menu The export attachment option after the export menu is selected

Run the script

After export, it needs to run a python script to import the exported markdown files to a notion page. md2notion and tqdm python packages need to be installed.

pip install md2notion tqdm

Three variable in the first lines have to be set properly to run the script without any errors.

token_v2 = "your_token_id"
page_url = "notion_url"
root_dir = "root_dir"
from notion.client import NotionClient
from md2notion.upload import upload
from notion.block import PageBlock
import io
from pathlib import Path
import glob
from tqdm import tqdm

client = NotionClient(token_v2=token_v2)
page = client.get_block(notion_url)

  • The value of page_url can be found from the url of the notion page.

  • The value of root_dir has to be where the exported markdown files are located.
for fname in tqdm(glob.glob("{root_dir}/**/*.md", recursive=True)):
    with open(fname, "r", encoding="utf-8") as mdFile:

        md_txt = mdFile.read().split("\n")
        page_title = md_txt[0].replace("#", "").strip()
        md_txt = "\n".join(md_txt[1:-1])

        mdFile = io.StringIO(md_txt)
        mdFile.__dict__["name"] = fname #Set this so we can resolve images later
        newPage = page.children.add_new(PageBlock, title=page_title)

        def convertImagePath(imagePath, mdFilePath):
            ret = Path(mdFilePath).parent / Path(mdFilePath).stem / Path(imagePath).name
            return ret
        upload(mdFile, newPage, imagePathFunc=convertImagePath)

bear-app-to-notion's People

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.