@@ -129,9 +129,12 @@ def posts_by_profile(
129129 timeout : int = DEFAULT_TIMEOUT_MEDIUM ,
130130 ) -> Union [ScrapeResult , List [ScrapeResult ]]:
131131 """Collect posts from Facebook profile URL (sync wrapper)."""
132- return asyncio .run (self .posts_by_profile_async (
133- url , num_of_posts , posts_to_not_include , start_date , end_date , timeout
134- ))
132+ async def _run ():
133+ async with self .engine :
134+ return await self .posts_by_profile_async (
135+ url , num_of_posts , posts_to_not_include , start_date , end_date , timeout
136+ )
137+ return asyncio .run (_run ())
135138
136139 # --- Trigger Interface (Manual Control) ---
137140
@@ -253,9 +256,12 @@ def posts_by_group(
253256 timeout : int = DEFAULT_TIMEOUT_MEDIUM ,
254257 ) -> Union [ScrapeResult , List [ScrapeResult ]]:
255258 """Collect posts from Facebook group URL (sync wrapper)."""
256- return asyncio .run (self .posts_by_group_async (
257- url , num_of_posts , posts_to_not_include , start_date , end_date , timeout
258- ))
259+ async def _run ():
260+ async with self .engine :
261+ return await self .posts_by_group_async (
262+ url , num_of_posts , posts_to_not_include , start_date , end_date , timeout
263+ )
264+ return asyncio .run (_run ())
259265
260266 # --- Trigger Interface (Manual Control) ---
261267
@@ -339,7 +345,10 @@ def posts_by_url(
339345 timeout : int = DEFAULT_TIMEOUT_MEDIUM ,
340346 ) -> Union [ScrapeResult , List [ScrapeResult ]]:
341347 """Collect detailed data from specific Facebook post URLs (sync wrapper)."""
342- return asyncio .run (self .posts_by_url_async (url , timeout ))
348+ async def _run ():
349+ async with self .engine :
350+ return await self .posts_by_url_async (url , timeout )
351+ return asyncio .run (_run ())
343352
344353 # --- Trigger Interface (Manual Control) ---
345354
@@ -434,9 +443,12 @@ def comments(
434443 timeout : int = DEFAULT_TIMEOUT_MEDIUM ,
435444 ) -> Union [ScrapeResult , List [ScrapeResult ]]:
436445 """Collect comments from Facebook post URL (sync wrapper)."""
437- return asyncio .run (self .comments_async (
438- url , num_of_comments , comments_to_not_include , start_date , end_date , timeout
439- ))
446+ async def _run ():
447+ async with self .engine :
448+ return await self .comments_async (
449+ url , num_of_comments , comments_to_not_include , start_date , end_date , timeout
450+ )
451+ return asyncio .run (_run ())
440452
441453 # --- Trigger Interface (Manual Control) ---
442454
@@ -537,9 +549,12 @@ def reels(
537549 timeout : int = DEFAULT_TIMEOUT_MEDIUM ,
538550 ) -> Union [ScrapeResult , List [ScrapeResult ]]:
539551 """Collect reels from Facebook profile URL (sync wrapper)."""
540- return asyncio .run (self .reels_async (
541- url , num_of_posts , posts_to_not_include , start_date , end_date , timeout
542- ))
552+ async def _run ():
553+ async with self .engine :
554+ return await self .reels_async (
555+ url , num_of_posts , posts_to_not_include , start_date , end_date , timeout
556+ )
557+ return asyncio .run (_run ())
543558
544559 # --- Trigger Interface (Manual Control) ---
545560
0 commit comments