From 3ed20fc19b58015b063b9cd9aac7cc7a41363792 Mon Sep 17 00:00:00 2001 From: dat-a-man <98139823+dat-a-man@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:09:52 +0530 Subject: [PATCH] Ag/notion source update (#242) * Create devcontainer.json * Deleted dev container * modified notion source to handle key error for "use_name" not provided. * Updated Return of get_database function and changed doc strings. * Removed whitespace from a blank line * reformated client.py --- sources/notion/__init__.py | 7 +++++++ sources/notion/helpers/client.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/sources/notion/__init__.py b/sources/notion/__init__.py index 9dcbb0933..a9ae92f62 100644 --- a/sources/notion/__init__.py +++ b/sources/notion/__init__.py @@ -39,6 +39,13 @@ def notion_databases( ] for database in database_ids: + if "use_name" not in database: + # Fetch the database details from Notion + details = notion_client.get_database(database["id"]) + + # Extract the name/title from the details + database["use_name"] = details["title"][0]["plain_text"] + notion_database = NotionDatabase(database["id"], notion_client) yield dlt.resource( # type: ignore notion_database.query(), diff --git a/sources/notion/helpers/client.py b/sources/notion/helpers/client.py index ef4bd3fa5..72a9fbbb6 100644 --- a/sources/notion/helpers/client.py +++ b/sources/notion/helpers/client.py @@ -151,3 +151,14 @@ def search( next_cursor = response.get("next_cursor") has_more = next_cursor is not None start_cursor = next_cursor + + def get_database(self, database_id: str) -> Any: + """Fetches the details of a specific database by its ID. + + Args: + database_id (str): The ID of the database to fetch. + + Returns: + Any: The details of the database. + """ + return self.fetch_resource("databases", database_id)