From 0ddb59e727ff5b712910c4ee3ea0802f6648e2ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 3 Nov 2025 05:56:06 +0000 Subject: [PATCH] Optimize MarkdownConverter by creating single instance at module level Co-authored-by: TheLovinator1 <4153203+TheLovinator1@users.noreply.github.com> --- scrape.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scrape.py b/scrape.py index 575668d..ff95398 100644 --- a/scrape.py +++ b/scrape.py @@ -50,6 +50,12 @@ CIRCLED_NUMBERS = { "⑩": ("10", re.compile(r"^\s*⑩\s*(.*?)\s*$", re.MULTILINE)), } +# Markdown converter instance - reuse instead of creating for each article +MARKDOWN_CONVERTER = MarkdownConverter( + heading_style="ATX", + strip=["pre", "code"], +) + async def fetch_json(url: str, client: httpx.AsyncClient) -> dict[Any, Any] | None: @@ -428,11 +434,7 @@ def generate_atom_feed(articles: list[dict[Any, Any]], file_name: str) -> str: if not article_content: article_content = article_title - converter: MarkdownConverter = MarkdownConverter( - heading_style="ATX", - strip=["pre", "code"], - ) - article_content_converted = str(converter.convert(article_content).strip()) # type: ignore # noqa: PGH003 + article_content_converted = str(MARKDOWN_CONVERTER.convert(article_content).strip()) # type: ignore # noqa: PGH003 if not article_content_converted: msg: str = f"Article content is empty for article ID: {article_id}"