How to use the notion.client.NotionClient function in notion

To help you get started, we’ve selected a few notion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kris-hansen / notion-cli / notioncli.py View on Github external
from contextlib import redirect_stdout
from contextlib import contextmanager
from io import StringIO

@contextmanager
def captureStdOut(output): 
    stdout = sys.stdout
    sys.stdout = output
    try:
        yield
    finally:
        sys.stdout = stdout

try:
    client = NotionClient(token_v2=os.environ['NOTION_TOKEN'], monitor=False)
except:
    cprint('NOTION_TOKEN / NOTION_PAGE environment variables not set or token expired.\n', 'red')
try:
    page = client.get_block(os.environ['NOTION_PAGE'])
except:
    cprint('NOTION_PAGE environment variables not set.\n', 'red')

    
def parse_task(string):
    taskn = string
    if isinstance(string, int):
        taskn = str(taskn)
    else:
        if ',' in string:
            taskn = string.split(',')
    value = taskn
github Cobertos / md2notion / md2notion / convert.py View on Github external
at notionPage
    """
    rendered = mistletoe.markdown(mdFile, notionPyRendererCls)
    for blockDescriptor in rendered:
        blockClass = blockDescriptor["type"]
        del blockDescriptor["type"]
        notionPage.children.add_new(blockClass, **blockDescriptor)
        #TODO: Support CollectionViewBlock

if __name__ == "__main__":
    import sys
    import os.path
    import glob
    from notion.block import PageBlock
    from notion.client import NotionClient
    client = NotionClient(token_v2=sys.argv[1])
    page = client.get_block(sys.argv[2])

    for fp in glob.glob(*sys.argv[3:], recursive=True):
        pageName = os.path.basename(fp)[:40]
        print(f"Converting {fp} to {pageName}")
        with open(fp, "r", encoding="utf-8") as f:
            newPage = page.children.add_new(PageBlock, title=pageName)
            convert(f, newPage)
github kevinjalbert / notion-toolbox / shared / notionscripts / notion_api.py View on Github external
def client(self):
        return NotionClient(token_v2=self.config.notion_token(), monitor=False)
github mayneyao / NotionPlus / app.py View on Github external
from flask import Flask, escape, request, Response
from flask_cors import CORS
from notion.client import NotionClient
from notion.collection import CollectionQuery
from notion.block import CodeBlock, EmbedOrUploadBlock
from notion.utils import remove_signed_prefix_as_needed

from actions import notion_plus


conf = ConfigParser()
conf.read('config.ini')
token = conf.get('notion', 'token')
timezone = conf.get('notion', 'timezone')
auth_token = conf.get('security', 'auth_token')
client = NotionClient(token_v2=token, timezone=timezone)

app = Flask(__name__)
CORS(app)


def get_notion_action_code(action_name, action_table_url):
    actions_cv = client.get_collection_view(action_table_url)

    action_block = None
    q = CollectionQuery(actions_cv.collection, actions_cv, action_name)
    for row in q.execute():
        print(row)
        action_block = row

    action_code = None
    for block in action_block.children:
github Cobertos / md2notion / md2notion / upload.py View on Github external
import sys
    from notion.block import PageBlock
    from notion.client import NotionClient

    parser = argparse.ArgumentParser(description='Uploads Markdown files to Notion.so')
    parser.add_argument('token_v2', type=str,
                        help='the token for your Notion.so session')
    parser.add_argument('page_url', type=str,
                        help='the url of the Notion.so page you want to upload your Markdown files to')
    parser.add_argument('md_path_url', type=str, nargs='+',
                        help='A path, glob, or url to the Markdown file you want to upload')

    args = parser.parse_args(sys.argv[1:])

    print("Initializing Notion.so client...")
    client = NotionClient(token_v2=args.token_v2)
    print("Getting target PageBlock...")
    page = client.get_block(args.page_url)

    for mdPath, mdFileName, mdFile in filesFromPathsUrls(args.md_path_url):
        # Make the new page in Notion.so
        pageName = mdFileName[:40]
        newPage = page.children.add_new(PageBlock, title=pageName)
        print(f"Uploading {mdPath} to Notion.so at page {pageName}...")
        upload(mdFile, newPage)