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.123]) by gnuweeb.org (Postfix) with ESMTPSA id E344C811E0; Thu, 20 Oct 2022 08:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666255152; bh=tA+b3zRn3x7b/zzX0CCWkZgSsCWSynBjxo/QQIT6Jr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sVicxc90kP4lVjlbEHfdtsrAQRVcYrdOohIwlIXEfSZAsjEv3e2n+Ndgjtx2CHaLI Uj8bOSxWzbweuk04MveSwR+NqOh55vZjUIqoHhdMplj34d7/0pqAZrDxQAPiU5cY8Z wDQJMam9pmW3o9q+wG5WtoUZkdNewF+tt5IGlZVKhiqDwpt60dzVJB85VYn4cFmy3Q JWs/udYBMmzGMi4daDGfFRgc0cruuqOCcZ2xmTJBcXvML0U+PEvp0gyJKu5y0C3q2u MB0vLavftqTYu9SdwV1mMn3Gi1a2yCAR0v84DhYmPr0i+LwFtSB6NWYCAueRBNEy+Y B/N5ZgR450obw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 5/8] atom: Improve remove_patch() Date: Thu, 20 Oct 2022 15:38:42 +0700 Message-Id: <20221020083845.907-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221020083845.907-1-kiizuha@gnuweeb.org> References: <20221020083845.907-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 c95612e..866c531 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