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.226]) by gnuweeb.org (Postfix) with ESMTPSA id 73A7A80827; Mon, 1 Aug 2022 00:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659313201; bh=FDC5K4AO50iGBCjRPihlTxEwofzIPVVg0jD7t2xHztc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a8Dyq5ygRzpdbaCB0IYl2CgkcIXv8RDchu/RiBlDaHzV7yqRnN/QMiBEd//axztjL 5b55QACCtF1h3+oNDrRq6k0c1n3UEoJLJfnZmWpk3Bz2BVXJwSRsP5Hv4TD5xBArYA kQyqEYz1ouGrfjutZDJ2EmGm87j/7ToLRHZ6O2cfWfSF7/QDlpkI1DxeiCEGEZaEUx lpt6nidDvFBClhcmbdAp52j1qC6ZxfU7lH7hUz6HsEZxewiaKS2THdwHk7LZiWEIsT 4urA3QATh82YRQEjoydw93c5zhLqo1+JteQ6172mEf2M04Osg6Oe0B7PmAdAI/hIis MTBtfdO1qfVAw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v5 10/19] Add delete_atom() function in scraper/db.py Date: Mon, 1 Aug 2022 07:19:08 +0700 Message-Id: <20220801001917.992-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220801001917.992-1-kiizuha@gnuweeb.org> References: <20220801001917.992-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