Skip to content

Commit 4c47ac3

Browse files
added dotenv to requirements
1 parent 489dd3d commit 4c47ac3

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

notion_graph/parser.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
from collections import defaultdict
99
from functools import wraps
10+
from pprint import pprint
1011
from typing import Any
1112
from typing import Awaitable
1213
from typing import Callable
@@ -65,7 +66,7 @@ def inner(_self: Parser, *args: Any, **kwargs: Any) -> None:
6566
class TaskQueue(asyncio.Queue[Task]):
6667
done: asyncio.Event
6768

68-
def __init__(self, num_worker: int = 16):
69+
def __init__(self, num_worker: int = 64):
6970
super().__init__()
7071
self.num_worker = num_worker
7172
self.done = asyncio.Event()
@@ -163,6 +164,7 @@ class Parser:
163164
task_queue = TaskQueue()
164165
graph: Graph
165166
parsed_blocks: set[str]
167+
parsed_blocks_lock = asyncio.Lock()
166168

167169
root_id: str
168170
max_workers: int
@@ -187,11 +189,6 @@ def parse(self) -> Graph:
187189

188190
@task
189191
async def parse_page(self, page_id: str) -> None:
190-
if page_id in self.parsed_blocks:
191-
return
192-
else:
193-
self.parsed_blocks.add(page_id)
194-
195192
def _parse_title(page_dict: dict[str, Any]) -> str:
196193
try:
197194
icon = cast(str, page_dict['icon']['emoji'])
@@ -239,9 +236,17 @@ async def parse_database(self, database_id: str) -> None:
239236
async def parse_children(self, block_id: str, page_id: str) -> None:
240237
children = (await get_children(block_id=block_id))['results']
241238
for block_dict in children:
242-
self._parse_block(block_dict=block_dict, block_id=block_id, page_id=page_id)
239+
await self._parse_block(
240+
block_dict=block_dict, block_id=block_dict['id'], page_id=page_id
241+
)
242+
243+
async def _parse_block(self, block_dict: dict, block_id: str, page_id: str) -> None:
244+
async with self.parsed_blocks_lock:
245+
if block_id in self.parsed_blocks:
246+
return
247+
else:
248+
self.parsed_blocks.add(block_id)
243249

244-
def _parse_block(self, block_dict: dict, block_id: str, page_id: str) -> None:
245250
def _get_relations(
246251
block_dict: dict, block_id: str, page_id: str
247252
) -> list[Relation]:
@@ -286,11 +291,12 @@ def _get_relations(
286291
return
287292

288293
elif block_dict['type'] == 'child_database':
294+
# logger.warning('child_database not implemented')
289295
return
290296

291297
else:
292298
if block_dict['has_children']:
293-
self.parsed_blocks.add(block_id)
299+
self.parse_children(block_id=block_id, page_id=page_id)
294300

295301
relations = _get_relations(block_dict, block_id, page_id)
296302
for relation in relations:

notion_graph/templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
let selfLoopLinks = {};
1212
let sameNodesLinks = {};
13-
const curvatureMinMax = 0.5;
13+
const curvatureMinMax = 0.25;
1414

1515
// 1. assign each link a nodePairId that combines their source and target independent of the links direction
1616
// 2. group links together that share the same two nodes or are self-loops
@@ -61,6 +61,7 @@
6161
.onNodeClick(node => window.open(`${node.url}`, '_blank'))
6262
.linkColor(() => 'rgba(255,255,255,0.2)')
6363
.linkCurvature('curvature')
64+
.d3AlphaDecay(0.01)
6465
.graphData(gData);
6566
});
6667
</script>

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
aiohttp
22
flask
3+
python-dotenv

t.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
async def amain():
12-
p = await get_children(block_id='453776be35854f74b098f7f6529ae33a')
12+
p = await get_children(block_id='2465521b79364efba808e29cde228616')
1313
pprint(p)
1414

1515

0 commit comments

Comments
 (0)