Skip to content

user

notion.user

RESEARCH_API_PATH module-attribute

RESEARCH_API_PATH = 'http://data.saige.in:8000/workspaces/notion/research_api_token.txt'

MEMBER_INFO_PATH module-attribute

MEMBER_INFO_PATH = '/NFS/workspaces/notion/git_to_notion_user.json'

get_token

get_token(token_path: str = RESEARCH_API_PATH)
Source code in ResearchToolkit/notion/common.py
def get_token(token_path: str = RESEARCH_API_PATH):
    if "http" in token_path:
        token = urlopen(token_path).read().decode("utf-8")
    else:
        with open(token_path, "r") as file:
            token = file.read()

    return token

get_notion_users

get_notion_users()
Source code in ResearchToolkit/notion/user.py
def get_notion_users():
    token = get_token(RESEARCH_API_PATH)

    headers = {
        "Authorization": f"Bearer {token}",
        "Notion-Version": "2022-06-28",
    }

    api_url = "https://api.notion.com/v1/users"

    response = requests.get(api_url, headers=headers)
    result = response.json()["results"]

    users = {
        user["name"]: {"id": user["id"], "email": user["person"]["email"]}
        for user in result
        if "person" in user
    }

    return users

get_git_user

get_git_user(repo_path)

get git user information (name and email) useful when collaborators share a database. can automatically specfiy editor of the database using git user info

Parameters:

  • repo_path (_type_) –

    git repo path

Returns:

  • _type_

    description

Source code in ResearchToolkit/notion/user.py
def get_git_user(repo_path):
    """get git user information (name and email)
       useful when collaborators share a database.
       can automatically specfiy editor of the database using git user info

    Args:
        repo_path (_type_): git repo path

    Returns:
        _type_: _description_
    """
    r = git.Repo.init(repo_path)
    reader = r.config_reader()
    user_name = reader.get_value("user", "name")
    user_email = reader.get_value("user", "email")
    return user_name, user_email

find_git

find_git(path)

find directory with .git file in parent directories. return None if not found.

Parameters:

  • path (_type_) –

    description

Returns:

  • _type_

    description

Source code in ResearchToolkit/notion/user.py
def find_git(path):
    """find directory with .git file in parent directories.
       return None if not found.

    Args:
        path (_type_): _description_

    Returns:
        _type_: _description_
    """
    if os.path.isdir(os.path.join(path, ".git")):
        return path
    else:
        if path in ["", "/"]:
            return None
        else:
            return find_git(os.path.dirname(path))