Source code for todosh_notion.todonotion
import argparse
import os
import shutil
from argparse import Namespace
from pathlib import Path
from notion.client import NotionClient
from todosh_notion.settings import TASK_LIST_URL, TOKEN_V2
[docs]def add(arg: Namespace) -> None:
"""Create a task in To Do
Task List
Parameters
----------
arg : Namespace
Arg with card title
"""
client = NotionClient(token_v2=TOKEN_V2)
page = client.get_collection_view(TASK_LIST_URL)
row = page.collection.add_row()
row.title = arg.title
row.status = "To Do"
[docs]def done(arg: Namespace) -> None:
"""Move all the tasks that have the "task" name into their titles to Done
Parameters
----------
arg : Namespace
Arg with card title
"""
client = NotionClient(token_v2=TOKEN_V2)
page = client.get_collection_view(TASK_LIST_URL)
for row in page.collection.get_rows(search=arg.title):
row.status = "Done"
[docs]def delete(arg: Namespace) -> None:
"""Like "done" command, but performs a delete action.
Delete all the tasks that have the "task" name into their titles
Parameters
----------
arg : Namespace
Arg with card title
"""
client = NotionClient(token_v2=TOKEN_V2)
page = client.get_collection_view(TASK_LIST_URL)
for row in page.collection.get_rows(search=arg.title):
row.remove()
[docs]def run():
parser = argparse.ArgumentParser(description="Manage cards in Notion task list")
subparsers = parser.add_subparsers(title="actions")
parser_add = subparsers.add_parser(
"add", add_help=False, help="Add a task in To Do"
)
parser_add.add_argument("title")
parser_add.set_defaults(func=add)
parser_done = subparsers.add_parser(
"done", add_help=False, help="Mark the task as Done"
)
parser_done.add_argument("title")
parser_done.set_defaults(func=done)
parser_delete = subparsers.add_parser(
"delete", add_help=False, help="Delete the task"
)
parser_delete.add_argument("title")
parser_delete.set_defaults(func=delete)
parser_configure = subparsers.add_parser(
"configure", add_help=False, help="Configure todo.sh actions"
)
parser_configure.set_defaults(func=configure)
argx = parser.parse_args()
argx.func(argx)
if __name__ == "__main__":
run()