From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.94]) by gnuweeb.org (Postfix) with ESMTPSA id E0AE37E254; Thu, 21 Jul 2022 23:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658446216; bh=86sEeRIjAaRHwzHJJp8B28kJMMbxSI5PH8Mo8+hUnzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=auu19vRipMNfyK3Ha+9V4y/ZaV/TCOQ9W2ckTpDJJyrM4VO1g6Gq4m77HfT+gNqIN /1bLwiXRVuAkV7n8WYqf/zShx7yTAnTsP14szU+arwP5dY1X61Gf1OGdC66WB+EXBM tcAOeI/eIJjSyGHeUgOAIOlHEtEqtibhCYS3DiFrCB0xZS3iwxWga+GfSkQ/g0UTPk gwyviGqz0B0RIzMvCKdHAHR9Cm0qD/r0OSNdRiJoz/FDIBK54xMRZ6H547IIYQebPc FTyzS388bX/0tWj0ft+QzCpW+6Y/B7J+N3u1qVpCPR5OzwtXBaq3M43fOcod1UshPB iZ8D/j4DF8FzA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v3 10/17] Create fix_utf8_chars function Date: Fri, 22 Jul 2022 06:29:31 +0700 Message-Id: <20220721232938.503-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220721232938.503-1-kiizuha@gnuweeb.org> References: <20220721232938.503-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: From: Muhammad Rizki Some of the codes are repeated, so I create this function to make it cleaner. Signed-off-by: Muhammad Rizki --- daemon/scraper/utils.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/daemon/scraper/utils.py b/daemon/scraper/utils.py index 5335fe2..30efb7b 100644 --- a/daemon/scraper/utils.py +++ b/daemon/scraper/utils.py @@ -182,12 +182,8 @@ def create_template(thread: Message, to=None, cc=None): if len(ret) >= 4000: ret = ret[:4000] + "..." - ret = ( - ret.rstrip() - .replace("<", "<") - .replace(">",">") - .replace("�"," ") - ) + "\n------------------------------------------------------------------------" + ret = fix_utf8_char(ret) + ret += "\n------------------------------------------------------------------------" return ret, files, is_patch @@ -211,13 +207,7 @@ def prepare_send_patch(mail, text, url): with open(file, "wb") as f: f.write(bytes(text, encoding="utf8")) - caption = ( - "#patch #ml\n" + - cap.rstrip() - .replace("<", "<") - .replace(">",">") - .replace("�"," ") - ) + caption = "#patch #ml\n" + fix_utf8_char(cap) return tmp, file, caption, url @@ -225,6 +215,15 @@ def clean_up_after_send_patch(tmp): shutil.rmtree(tmp) +def fix_utf8_char(text: str): + return ( + text.rstrip() + .replace("<", "<") + .replace(">",">") + .replace("�"," ") + ) + + EMAIL_MSG_ID_PATTERN = r"<([^\<\>]+)>" def extract_email_msg_id(msg_id): ret = re.search(EMAIL_MSG_ID_PATTERN, msg_id) -- Muhammad Rizki