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.87]) by gnuweeb.org (Postfix) with ESMTPSA id 0B1CA81123; Tue, 18 Oct 2022 08:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666081063; bh=Tf10JgLm/helMpizanGH3jfXNJSdKo2K/A9w46cQE5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SAJIIbr5oJuL1e6/QGL5xB4OlHTVREWuo4Gqsx20HfLWVJ2I6MDuprbOEXgkeFoj/ kNW1afCfyWwUY3wKhL2Fw6JTfMSGYlAdXbSLGOkfUtkFiWiAiVNOPO2HfqSaGESLxK pDs82YSw7hkjPBFfw1b31zVvGTbywocfE0Ui87rnyA4zAGOJ20ikD/GDtIhX+nS+/W M+Gj5MTQ42CckiY0LKfy/0JBbeJPnc2YIiC/Hug7/WTYby5j73LW2BkVvGNx/aSONc +71KXOj3HAznNi45IQ8Po0GsqSubSTHwLoHHR5t35xr/iNr4nT8hNz9nTCoRvwR1Af MPBObBPVhwstA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 5/7] atom: Improve remove_patch() Date: Tue, 18 Oct 2022 15:16:33 +0700 Message-Id: <20221018081635.1617-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221018081635.1617-1-kiizuha@gnuweeb.org> References: <20221018081635.1617-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Improvement on remove_patch(). So, after send all the email attachments then remove them. On the previous patch, this function can't remove them properly. Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 10 +++++++--- daemon/dscord/mailer/listener.py | 4 ++-- daemon/telegram/mailer/listener.py | 3 +-- daemon/telegram/packages/plugins/commands/scrape.py | 3 +-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index 48857a7..c129925 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -6,7 +6,7 @@ from pyrogram.types import Chat, InlineKeyboardMarkup, InlineKeyboardButton from email.message import Message -from typing import Dict +from typing import Dict, Union from slugify import slugify import hashlib import uuid @@ -238,8 +238,12 @@ def prepare_patch(mail, text, url, platform: str): return tmp, file, caption, url -def remove_patch(tmp): - shutil.rmtree(tmp) +def remove_patch(tmp: Union[str, list]): + if isinstance(tmp, str): + return shutil.rmtree(tmp) + + for d,_ in tmp: + shutil.rmtree(d) def fix_utf8_char(text: str, unescape: bool = True): diff --git a/daemon/dscord/mailer/listener.py b/daemon/dscord/mailer/listener.py index a280a58..cc0a9f7 100644 --- a/daemon/dscord/mailer/listener.py +++ b/daemon/dscord/mailer/listener.py @@ -125,10 +125,10 @@ class Listener: for d, f in files: await m.reply(file=File(f"{d}/{f}")) - if files.index((d,f)) == len(files)-1: - utils.remove_patch(d) await asyncio.sleep(1) + utils.remove_patch(files) + return True diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 208aed0..08feddd 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -118,8 +118,7 @@ class Bot(): await m.reply_document(f"{d}/{f}", file_name=f) await asyncio.sleep(1) - if files: - shutil.rmtree(str(files[0][0])) + utils.remove_patch(files) return True diff --git a/daemon/telegram/packages/plugins/commands/scrape.py b/daemon/telegram/packages/plugins/commands/scrape.py index d4d10a9..52ddb0b 100644 --- a/daemon/telegram/packages/plugins/commands/scrape.py +++ b/daemon/telegram/packages/plugins/commands/scrape.py @@ -53,5 +53,4 @@ async def scrap_email(c: DaemonClient, m: Message): await m.reply_document(f"{d}/{f}", file_name=f) await asyncio.sleep(1) - if files: - shutil.rmtree(str(files[0][0])) + utils.remove_patch(files) -- Muhammad Rizki