1
- import enum
1
+ import concurrent
2
2
import json
3
3
import logging
4
4
import multiprocessing
5
5
import os
6
6
import shutil
7
7
import time
8
+ from concurrent .futures import ThreadPoolExecutor
8
9
from datetime import datetime
9
- from multiprocessing import Pool , freeze_support
10
10
11
11
import requests
12
12
from tqdm import tqdm
13
13
14
14
15
- class ExportType (enum . StrEnum ):
15
+ class ExportType ():
16
16
MARKDOWN = "markdown"
17
17
HTML = "html"
18
18
PDF = "pdf"
19
19
20
20
21
- class ViewExportType (enum . StrEnum ):
21
+ class ViewExportType ():
22
22
CURRENT_VIEW = "currentView"
23
23
ALL = "all"
24
24
@@ -77,10 +77,10 @@ def _export(self, id):
77
77
url = "https://www.notion.so/api/v3/enqueueTask"
78
78
id = self ._to_uuid_format (s = id )
79
79
export_options = {
80
- "exportType" : self .export_type . value ,
80
+ "exportType" : self .export_type ,
81
81
"locale" : "en" ,
82
82
"timeZone" : "Europe/London" ,
83
- "collectionViewExportType" : self .current_view_export_type . value ,
83
+ "collectionViewExportType" : self .current_view_export_type ,
84
84
"flattenExportFiletree" : self .flatten_export_file_tree ,
85
85
}
86
86
@@ -184,11 +184,12 @@ def _unpack(self):
184
184
185
185
def process (self ):
186
186
logging .info (f"Exporting { len (self .pages )} pages..." )
187
- with Pool (processes = self .workers ) as pool :
187
+
188
+ with ThreadPoolExecutor (max_workers = self .workers ) as executor :
188
189
with tqdm (total = len (self .pages ), dynamic_ncols = True ) as pbar :
189
- for result in pool . imap_unordered (
190
- self . _process_page , self . pages . items ()
191
- ):
190
+ futures = { executor . submit ( self . _process_page , item ): item for item in self . pages . items ()}
191
+ for future in concurrent . futures . as_completed ( futures ):
192
+ result = future . result ()
192
193
if result ["state" ] == "failure" :
193
194
continue
194
195
name = result ["name" ]
@@ -200,7 +201,3 @@ def process(self):
200
201
pbar .update (1 )
201
202
202
203
self ._unpack ()
203
-
204
-
205
- if __name__ == "__main__" :
206
- freeze_support ()
0 commit comments