1- import enum
1+ import concurrent
22import json
33import logging
44import multiprocessing
55import os
66import shutil
77import time
8+ from concurrent .futures import ThreadPoolExecutor
89from datetime import datetime
9- from multiprocessing import Pool , freeze_support
1010
1111import requests
1212from tqdm import tqdm
1313
1414
15- class ExportType (enum . StrEnum ):
15+ class ExportType ():
1616 MARKDOWN = "markdown"
1717 HTML = "html"
1818 PDF = "pdf"
1919
2020
21- class ViewExportType (enum . StrEnum ):
21+ class ViewExportType ():
2222 CURRENT_VIEW = "currentView"
2323 ALL = "all"
2424
@@ -77,10 +77,10 @@ def _export(self, id):
7777 url = "https://www.notion.so/api/v3/enqueueTask"
7878 id = self ._to_uuid_format (s = id )
7979 export_options = {
80- "exportType" : self .export_type . value ,
80+ "exportType" : self .export_type ,
8181 "locale" : "en" ,
8282 "timeZone" : "Europe/London" ,
83- "collectionViewExportType" : self .current_view_export_type . value ,
83+ "collectionViewExportType" : self .current_view_export_type ,
8484 "flattenExportFiletree" : self .flatten_export_file_tree ,
8585 }
8686
@@ -184,11 +184,12 @@ def _unpack(self):
184184
185185 def process (self ):
186186 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 :
188189 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 ()
192193 if result ["state" ] == "failure" :
193194 continue
194195 name = result ["name" ]
@@ -200,7 +201,3 @@ def process(self):
200201 pbar .update (1 )
201202
202203 self ._unpack ()
203-
204-
205- if __name__ == "__main__" :
206- freeze_support ()
0 commit comments