-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve collecting data from Notion
- Loading branch information
1 parent
7be4827
commit 9830b87
Showing
11 changed files
with
129 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
parameters: | ||
database_ids: | ||
- 7ec04ecd2d00406284674b1a614f1ec7 | ||
- 7ec04ecd2d00406284674b1a614f1ec7 | ||
# - 140bc009043f80e1b14bd568381b93a8 | ||
# - 6d8dd6ae29c442b1baea9c610dd1e92d | ||
# - 20438dae7f8842838593af3411754867 | ||
# - e9b2f80fb10e474ba95c7c219c9c6462 | ||
# - be6505f5e7544b66a75fe0d444aba1b2 | ||
# - f54dbddcaa4c43c7ae17935716761536 | ||
# - 31fcaab5a9404d41b922897d32b901b3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .page import Page | ||
|
||
__all__ = ["Page"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Page(BaseModel): | ||
content: str | ||
metadata: dict | ||
|
||
def write(self, file_path: Path) -> None: | ||
with open(file_path, "w", encoding="utf-8") as f: | ||
json.dump( | ||
{"content": self.content, "metadata": self.metadata}, | ||
f, | ||
indent=4, | ||
ensure_ascii=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def merge_dicts(dict1: dict, dict2: dict) -> dict: | ||
"""Recursively merge two dictionaries with list handling.""" | ||
result = dict1.copy() | ||
|
||
for key, value in dict2.items(): | ||
if key in result: | ||
if isinstance(result[key], dict) and isinstance(value, dict): | ||
result[key] = merge_dicts(result[key], value) | ||
elif isinstance(result[key], list) and isinstance(value, list): | ||
result[key] = result[key] + value | ||
else: | ||
result[key] = value | ||
else: | ||
result[key] = value | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import shutil | ||
from pathlib import Path | ||
|
||
from zenml import step | ||
|
||
from second_brain.entities import Page | ||
|
||
|
||
@step | ||
def save_notion_pages( | ||
database_id: str, | ||
pages: dict[str, str], | ||
pages: dict[str, Page], | ||
) -> None: | ||
output_dir = Path("data") / database_id | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
if output_dir.exists(): | ||
shutil.rmtree(output_dir) | ||
output_dir.mkdir(parents=True) | ||
|
||
for page_name, content in pages.items(): | ||
file_path = output_dir / f"{page_name}.txt" | ||
with open(file_path, "w", encoding="utf-8") as f: | ||
f.write(content) | ||
for page_id, page in pages.items(): | ||
file_path = output_dir / f"{page_id}.json" | ||
page.write(file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
"paragraph", | ||
"heading_3", | ||
"heading_1", | ||
"heading_2", | ||
"child_page", | ||
"image", | ||
"divider", | ||
"code", | ||
"link_preview", | ||
"bulleted_list_item", | ||
"numbered_list_item" | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.