Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(property-converter): unique_id #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: toggle properties export
  • Loading branch information
nilleb committed Nov 7, 2024
commit 06a670bfc21972ecbe562d82b8d68cb5a829dbaa
20 changes: 15 additions & 5 deletions notion_exporter/exporter.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from typing import Optional
import asyncio
import logging
from typing import Optional

from notion_client import AsyncClient as NotionClient, APIResponseError
from notion_client import APIResponseError
from notion_client import AsyncClient as NotionClient
from notion_client import Client
from notion_client.helpers import async_collect_paginated_api
from tenacity import retry, retry_if_exception, stop_after_attempt, wait_exponential

from notion_exporter.block_converter import BlockConverter
from notion_exporter.property_converter import PropertyConverter
from notion_exporter.retry_utils import is_rate_limit_exception, wait_for_retry_after_header, is_unavailable_exception

from notion_exporter.retry_utils import (
is_rate_limit_exception,
is_unavailable_exception,
wait_for_retry_after_header,
)

logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s", datefmt="%m/%d/%Y %I:%M:%S %p")
logger = logging.getLogger(__name__)
Expand All @@ -26,19 +30,22 @@ def __init__(
notion_token: str,
export_child_pages: bool = False,
extract_page_metadata: bool = False,
extract_page_properties: bool = False,
exclude_title_containing: Optional[str] = None,
):
"""
:param notion_token: Notion API token.
:param export_child_pages: Whether to export child pages. Default: True.
:param extract_page_metadata: Whether to extract page metadata. Default: False.
:param exclude_title_containing: If specified, pages with titles containing this string will be excluded.
:param extract_page_properties: Whether to extract page properties. Default: False.

"""
self.notion = NotionClient(auth=notion_token)
self.sync_notion = Client(auth=notion_token)
self.export_child_pages = export_child_pages
self.extract_page_metadata = extract_page_metadata
self.extract_page_properties = extract_page_properties
self.exclude_title_containing = exclude_title_containing
self.block_converter = BlockConverter()
self.property_converter = PropertyConverter(self)
Expand Down Expand Up @@ -411,7 +418,7 @@ def _get_page_front_matter(self, page_meta: dict, page_paths: dict, parent_page_
front_matter += "---\n\n"

# Add properties of database entries as key-value pairs
if "properties" in page_meta:
if self.extract_page_properties and "properties" in page_meta:
for prop_name, prop in page_meta["properties"].items():
front_matter += f"{prop_name}: {prop}\n"
front_matter += "\n"
Expand Down Expand Up @@ -477,3 +484,6 @@ def _normalize_id(notion_id: str) -> str:
logger.warning("Notion ID is not in the expected format. ID: %s", notion_id)

return notion_id
logger.warning("Notion ID is not in the expected format. ID: %s", notion_id)

return notion_id