optimize download -> parse process

This commit is contained in:
Arian Nasr
2025-12-11 04:34:06 -05:00
parent 25469a54b3
commit 0997005994
4 changed files with 16 additions and 16 deletions

View File

@@ -1,9 +1,9 @@
from pathlib import Path
from playwright.async_api import async_playwright
from schemas import DownloadParameters
from io import BytesIO
async def download_xml_files(params: DownloadParameters) -> Path:
async def download_xml_files(params: DownloadParameters) -> BytesIO:
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
@@ -60,7 +60,12 @@ async def download_xml_files(params: DownloadParameters) -> Path:
# Perform the action that initiates download
await download_button.click()
download = await download_info.value
download_path = params.output_dir / download.suggested_filename
await download.save_as(download_path)
filepath = await download.path()
with open(filepath, 'rb') as f:
xml_file = BytesIO(f.read())
await download.delete()
await browser.close()
return download_path
return xml_file