jamalex / notion-py

Unofficial Python API client for Notion.so
MIT License
4.3k stars 473 forks source link

Having issues creating a new task with tags #229

Open Nick-Mazuk opened 3 years ago

Nick-Mazuk commented 3 years ago

For some reason whenever I create a new task with specified tags, the tags aren't saved into Notion.

Here's the code I'm using. It tasks a string such as "this is the name of the task #tag !high" and correctly parses that it has the tags ["tag"], a priority of ["high"], and a name of "this is the name of the task". However, while Notion is saving the priority and name, but not the tags. Am I doing anything wrong? From what I can tell by reading the docs, this should work.

I've tested this with tags that are already defined in Notion.

import argparse
import sys
from notion.client import NotionClient

parser = argparse.ArgumentParser()
parser.add_argument("query")

args = parser.parse_args()

query = args.query

if(query != ''):
    def extract_meta_data(splitQuery, keyString, options=[]):
        final_list = list(set(part[len(keyString):] for part in splitQuery if (part.startswith(keyString) and (len(options) == 0 or (part[len(keyString):] in options)))))
        for item in final_list:
            splitQuery.remove(keyString + item)
        return final_list

    def get_first_item(array):
        if len(array) != 0:
            return array[0]
        return

    client = NotionClient(token_v2="<token>")
    cv = client.get_collection_view("<collection URL>")

    splitQuery = query.split()

    tags = extract_meta_data(splitQuery, '#')
    priority = get_first_item(extract_meta_data(splitQuery, '!', ['urgent', 'high', 'medium', 'low']))

    row = cv.collection.add_row()
    row.name = ' '.join(splitQuery)
    row.tags = tags
    row.priority = priority

This script is run with this command and args

python3 main.py "this is the name of the task #tag !high"

This is the full source code.

HacDan commented 3 years ago

Could you provide a notion template to test against? Your code works for me with predefined tags.

Also do you receive any error output when running this?