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.57]) by gnuweeb.org (Postfix) with ESMTPSA id 999777FBEE; Tue, 19 Jul 2022 00:18:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658189911; bh=IxfQ2EObRH9rwrazzn35ONQR7d2dIstBze5XVxpjW7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HstgE73mKi+toz0QW6oGEnDG79inkoLCWMXjMSVrj2AaBqeIznlADAXd4T1zXYov+ bnH8pXkr5bk9PjyEdTV6bFa788egPvmVEBTR1DlwwNQDOabIhVysWEfx1TJDAksID/ 58rrLi+fTIi9/WDgUY0i3GxCWgGotuHTMZWXvfgZFoJzDEkhD24MAXPZ0KfGRqnerC Zupro3EObE4EfCdq4LvpJdsl0HYz8sxVpL073NyPwPjFJ1yJtu8MYrgkFYpbOxOPJg bqvZyfy4jdNTZ3i55Fa5HS3w1ZjlgDZXDFd22dxweGZICnFGAc4NZbvt1vCi3nRlvJ M8CjovmMQFb3g== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 14/18] Remove prepare patch and clean up patch Date: Tue, 19 Jul 2022 07:17:40 +0700 Message-Id: <20220719001744.1950-15-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220719001744.1950-1-kiizuha@gnuweeb.org> References: <20220719001744.1950-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: From: Muhammad Rizki These functions already moved to scaper/utils.py, so I decide to remove it in scaper/bot.py and change some of the code that required to change. Signed-off-by: Muhammad Rizki --- daemon/scraper/bot.py | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/daemon/scraper/bot.py b/daemon/scraper/bot.py index 33a9eaa..1abfa98 100644 --- a/daemon/scraper/bot.py +++ b/daemon/scraper/bot.py @@ -160,50 +160,15 @@ class Bot(): async def __send_patch_msg(self, mail, tg_chat_id, reply_to, text, url): print("[__send_patch_msg]") - tmp, doc, caption, url = Bot.prepare_send_patch(mail, text, url) + tmp, doc, caption, url = utils.prepare_send_patch(mail, text, url) ret = await self.__handle_telegram_floodwait( self.client.send_patch_email, *[tg_chat_id, doc, caption, reply_to, url] ) - Bot.clean_up_after_send_patch(tmp) + utils.clean_up_after_send_patch(tmp) return ret - @staticmethod - def prepare_send_patch(mail, text, url): - tmp = utils.gen_temp(url) - fnm = str(mail.get("subject")) - sch = re.search(utils.PATCH_PATTERN, fnm, re.IGNORECASE) - - nr_patch = sch.group(1) - if not nr_patch: - nr_patch = 1 - else: - nr_patch = int(nr_patch) - - num = "%04d" % nr_patch - fnm = slugify(sch.group(3)).replace("_", "-") - file = f"{tmp}/{num}-{fnm}.patch" - cap = text.split("\n\n")[0] - - with open(file, "wb") as f: - f.write(bytes(text, encoding="utf8")) - - caption = ( - "#patch #ml\n" + - cap.rstrip() - .replace("<", "<") - .replace(">",">") - .replace("�"," ") - ) - return tmp, file, caption, url - - - @staticmethod - def clean_up_after_send_patch(tmp): - shutil.rmtree(tmp) - - async def __send_text_msg(self, *args): return await self.__handle_telegram_floodwait( self.client.send_text_email, -- Muhammad Rizki