def block_delete(notion_token, block_id): try: notion_api = NotionApi(notion_token) block = notion_api.block_delete(block_id) return jsonify(block), 200 except Exception as error: return jsonify(error=str(error)), 500
def collection_append(notion_token, collection_id, view_id): try: notion_api = NotionApi(notion_token) row = notion_api.collection_append(collection_id, view_id, request.json) return jsonify(row=row), 200 except Exception as error: return jsonify(error=str(error)), 500
def block_view(notion_token, block_id): try: notion_api = NotionApi(notion_token) content = notion_api.block_content(block_id) return jsonify(content=content), 200 except Exception as error: return jsonify(error=str(error)), 500
def collection_view(notion_token, collection_id, view_id): try: notion_api = NotionApi(notion_token) content = notion_api.collection_view(collection_id, view_id) return jsonify(rows=content), 200 except Exception as error: return jsonify(error=str(error)), 500
def test_block_append(notion_token): notion_api = NotionApi(token=notion_token) test_page = get_test_page() block = test_page.children.add_new(TextBlock, title="test block append") new_block = notion_api.block_append(block.id, {"title": "appending text"}) assert new_block == {"id": new_block.block.id, "title": "appending text"} assert new_block.block.parent.id == block.id
def test_block_content(notion_token): notion_api = NotionApi(token=notion_token) test_page = get_test_page() block = test_page.children.add_new(TextBlock, title="test get block content") content = notion_api.block_content(block.id) assert content == {"id": block.id, "title": "test get block content"}
def add_note(): try: notion_api = NotionApi() notion_api.append_to_current_day_notes(request.json['title']) return 'Succeceed in adding note', 200 except Exception: return 'Failed in adding note', 500
def block_append(notion_token, block_id): try: notion_api = NotionApi(notion_token) block = notion_api.block_append(block_id, request.json['text']) return jsonify(block_id=block.id), 200 except Exception as error: return jsonify(error=str(error)), 500
def test_block_update(notion_token): notion_api = NotionApi(token=notion_token) test_page = get_test_page() block = test_page.children.add_new(TextBlock, title="test block update") updated_block = notion_api.block_update(block.id, "test block has been updated") assert updated_block.title == "test block has been updated" assert updated_block.id == block.id
def test_block_delete_with_collection_block(notion_token): notion_api = NotionApi(token=notion_token) collection_view = create_collection_view() block = collection_view.collection.add_row(name="test row", value=10, enabled=True) notion_api.block_delete(block.id) assert block not in collection_view.collection.get_rows()
def test_block_delete_with_text_block(notion_token): notion_api = NotionApi(token=notion_token) test_page = get_test_page() block = test_page.children.add_new(TextBlock, title="test block delete") parent_block = block.parent notion_api.block_delete(block.id) parent_block.refresh() assert block not in parent_block.children
def get_current_tasks(): try: notion_api = NotionApi() current_tasks = [] for task in notion_api.get_current_tasks(): current_tasks.append({'id': task.id, 'title': task.title}) return jsonify(tasks=current_tasks) except Exception: return 'Failed fetching current tasks', 500
def add_task(): try: notion_api = NotionApi() collection = notion_api.tasks_database().collection row = collection.add_row() row.name = request.json['title'] return 'Succeceed in adding task', 200 except Exception: return 'Failed in adding task', 500
def test_block_update_with_text_block(notion_token): notion_api = NotionApi(token=notion_token) test_page = get_test_page() block = test_page.children.add_new(TextBlock, title="test block update") updated_block = notion_api.block_update( block.id, {"title": "test block has been updated"}) assert updated_block == { "id": block.id, "title": "test block has been updated" }
def test_block_children(notion_token): notion_api = NotionApi(token=notion_token) test_page = get_test_page() block = test_page.children.add_new(TextBlock, title="a parent block") child_block_1 = block.children.add_new(TextBlock, title="child block 1") child_block_2 = block.children.add_new(TextBlock, title="child block 2") content = notion_api.block_children(block.id) assert content[0] == {"id": child_block_1.id, "title": "child block 1"} assert content[1] == {"id": child_block_2.id, "title": "child block 2"}
def test_collection_view_content(notion_token): notion_api = NotionApi(token=notion_token) collection_view = create_collection_view() collection_id = collection_view.parent.id.replace("-", "") view_id = collection_view.id.replace("-", "") collection_view.collection.add_row(name="test row") collection_view_content = notion_api.collection_view_content( collection_id, view_id) assert collection_view_content[0]["name"] == "test row"
def update_light(): try: notion_api = NotionApi() current_day = datetime.now().strftime("%A") block = notion_api.get_block(request.json['lightId']) setattr(block, current_day, request.json['value']) return 'Succeceed in updating light', 200 except Exception: return 'Failed updating light', 500
def get_links(): try: notion_api = NotionApi() current_day = notion_api.current_day() current_week = notion_api.current_week() return jsonify( current_day=app_url(current_day.get_browseable_url()), current_week=app_url(current_week.get_browseable_url()), ) except Exception: return 'Failed fetching current links', 500
def get_current_lights(): try: notion_api = NotionApi() current_lights = [] for light in notion_api.current_day_lights(): current_lights.append({'id': light["url"], 'title': light["title"]}) print(current_lights) return jsonify( lights=current_lights ) except Exception: return 'Failed fetching current lights', 500
def add_task(): try: notion_api = NotionApi() collection = notion_api.tasks_database().collection row = collection.add_row() row.name = request.json['title'] row.status = 'Next Up' row.tags = [notion_api.config.imported_tag_url()] return 'Succeceed in adding task', 200 except Exception: return 'Failed in adding task', 500
def test_collection_view_append(notion_token): notion_api = NotionApi(token=notion_token) collection_view = create_collection_view() collection_id = collection_view.parent.id.replace("-", "") view_id = collection_view.id.replace("-", "") notion_api.collection_append(collection_id, view_id, { "enabled": True, "value": 10, "name": "test row" }) collection_view_content = notion_api.collection_view_content( collection_id, view_id) assert collection_view_content[0]["name"] == "test row" assert collection_view_content[0]["enabled"] is True assert collection_view_content[0]["value"] == 10
def add_task(): try: notion_api = NotionApi() collection = notion_api.tasks_database().collection # HACK: For some reason, we need all the views loaded up for the collection.add_row() to work # it also has to be 'printed' for whatever reason, just accessing it doesn't work # https://github.com/jamalex/notion-py/issues/92 print(collection.parent.views) row = collection.add_row() row.name = request.json['title'] row.status = 'Next Up' row.tags = [notion_api.config.imported_tag_url()] return 'Succeceed in adding task', 200 except Exception: return 'Failed in adding task', 500
def test_block_update_with_collection_block(notion_token): notion_api = NotionApi(token=notion_token) collection_view = create_collection_view() block = collection_view.collection.add_row(name="test row", value=10, enabled=True) updated_block = notion_api.block_update(block.id, { "name": "test block has been updated", "value": 5 }) assert updated_block == { "id": block.id, "name": "test block has been updated", "value": 5, "category": None, "enabled": True, "tags": [] }
#!/usr/local/bin/python3 from notionscripts.notion_api import NotionApi api = NotionApi() def app_url(browser_url): return browser_url.replace("https://", "notion://") message = None for row in api.get_current_tasks(): message = "%s | href=%s" % (row.title, app_url(row.get_browseable_url())) print(message) if message is None: message = "Working on Nothing | href=%s" % app_url( api.current_day().get_browseable_url()) print(message)
def polling_task_processors(): notion_api = NotionApi() PollingTaskProcessors(notion_api).run()
from notionscripts.notion_api import NotionApi from config import Config notion_api = NotionApi(Config()) config = notion_api.config
def transition_tasks(): NotionApi().transition_tasks()