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 38D45806D7; Fri, 29 Jul 2022 00:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055341; bh=FDC5K4AO50iGBCjRPihlTxEwofzIPVVg0jD7t2xHztc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OWAXT6i0q8UiMGciKJrcAP8u2wrO/5ZytGbQDXVQ317pW3YbCHOT9yt5X7CwKlZ9I EoiZzlihcoroO2S8RqMMP3v1m9OmHLgu7Vy0xV5gPh6gKGUfZBPy5EK3ns5au5MVsH TljmMWhCM5A5T6Oc5gz4puRIH/F/mVDGnOxVsDMZt+HRGRTbtZXR5SpbZanIzMJRLn ZJzhKhEdgGOx9kXGrR8j8H3ZyXSW2js5bNtzaEpzhyYXWy21hm8A11RN+u4gS9E/gQ sPu9QmNw0ccYBGL3qtIHmXUwCK7agOLxZVCJvIspLT+kw9Gc4EddR2LxH1NpxEvCVE JZNi4JyR9Vwcw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 09/18] Add delete_atom() function in scraper/db.py Date: Fri, 29 Jul 2022 07:40:37 +0700 Message-Id: <20220729004046.1890-29-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220729004046.1890-1-kiizuha@gnuweeb.org> References: <20220729004046.1890-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add delete_atom() function to remove atom URL in database Signed-off-by: Muhammad Rizki --- daemon/packages/plugins/manage_atom.py | 19 ++++++++++++++++++- daemon/scraper/db.py | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/daemon/packages/plugins/manage_atom.py b/daemon/packages/plugins/manage_atom.py index 934aba9..0d2166a 100644 --- a/daemon/packages/plugins/manage_atom.py +++ b/daemon/packages/plugins/manage_atom.py @@ -3,7 +3,7 @@ # Copyright (C) 2022 Muhammad Rizki # -from pyrogram.types import Message +from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton from pyrogram import filters from packages import DaemonClient from scraper import utils @@ -28,3 +28,20 @@ async def add_atom_url(c: DaemonClient, m: Message): return await m.reply(f"This URL already listened for new email.") await m.reply(f"Success add **{text}** for listening new email") + + +@DaemonClient.on_message( + filters.command("del_atom") & + filters.chat(["kiizuah", "nekoha", -1001673279485]) +) +async def del_atom_url(c: DaemonClient, m: Message): + atoms = c.db.get_atom_urls() + if len(atoms) == 0: + return await m.reply("Currently empty.") + + text = "List of atom URL that currently listened:\n" + for u,i in zip(atoms, range(1, len(atoms)+1)): + text += f"{i}. {u}\n" + + text += "\nChoose one of the URL above to delete by index below." + await m.reply(text) diff --git a/daemon/scraper/db.py b/daemon/scraper/db.py index 30ed9a7..24fc2c6 100644 --- a/daemon/scraper/db.py +++ b/daemon/scraper/db.py @@ -130,6 +130,18 @@ class Db(): return self.cur.lastrowid + def delete_atom(self, atom: str): + q = """ + DELETE FROM atom_urls + WHERE url = %(atom)s + """ + try: + self.cur.execute(q, {"atom": atom}) + return True + except: + return False + + def get_atom_urls(self): q = """ SELECT atom_urls.url -- Muhammad Rizki