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.157]) by gnuweeb.org (Postfix) with ESMTPSA id E19D28060F; Sat, 30 Jul 2022 04:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659156054; bh=FDC5K4AO50iGBCjRPihlTxEwofzIPVVg0jD7t2xHztc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mi8efWoXVIfVQRDykMLZcg+qik9d5LHzumx6UsxqrNFSboat3y2HTho023WV87OZf gK22CGyN44XlAIeqLx4Qr2uPaecEhDQbLBcsn40C2m9l2hatbTIM++DRTs+UKg7zM2 ZdURBgpbTvNyrirWxG+55ShTuGwk8g+jWD0i3uJahra500KAv3VYUACCJS5UExHO8v kgNA8U9gsD/ON4BBWKk1fjjIVbGjJDCsfZaTYeYhFZ7Ho0Oct1ZI8ZTatmxPyj0hb1 4svmegSBCYgLF/C5lqrCkHZQfCzjqzbhq0YlFP/PnH/0S22nqiQXRwhRhe5B+Qku5T Qwh3GOKn0hNsg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v4 09/18] Add delete_atom() function in scraper/db.py Date: Sat, 30 Jul 2022 11:40:07 +0700 Message-Id: <20220730044016.988-10-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220730044016.988-1-kiizuha@gnuweeb.org> References: <20220730044016.988-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