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 78A727E257; Mon, 1 Aug 2022 00:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659313184; bh=csV4IgpcwsmtfrkTGLCHmzQUWtSayhhcIdjtFPoNbB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=euZnSV1jb+daJbxOlyZMM/pjiQTujR7EcpLjVVvzos31qFI2ss43QQlVCk/UpPpU1 b1T5wNwl3cG1DFmwfNmQ/dDX5WC68qp8rGbrE0JOSyNep/oi8PcTuQJjoNPSTI6qfE xAhBAFTRFYP6ifcbEj8WF6BHlxK3rjkqN2YrTJfgfx4lB51pAnRXRG3REfesLX5F2s tWN8ymXqMLr+QC+ixMBmJav2XMu5vSeGYXgY7eI1pmzEKv6mT8UBaLQ+2NfLNhgE/w E5rk6m5g/SiY+LDbmsYuoXkNjPfhLX8UgrntAMgWDJszNjbOi9hSg+mBTxSF00berT vKBEVoNqOX7sQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v5 03/19] Add ATOM_URLS and BROADCAST_CHAT methods Date: Mon, 1 Aug 2022 07:19:01 +0700 Message-Id: <20220801001917.992-4-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: I decided to add ATOM_URLS and BROADCAST_CHAT methods to get their content in database which will be handle in scraper/bot.py Signed-off-by: Muhammad Rizki --- daemon/scraper/bot.py | 17 ++++------------- daemon/scraper/db.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/daemon/scraper/bot.py b/daemon/scraper/bot.py index bc9d575..c475e34 100644 --- a/daemon/scraper/bot.py +++ b/daemon/scraper/bot.py @@ -21,16 +21,6 @@ class BotMutexes(): class Bot(): - ATOM_URLS = [ - "https://lore.kernel.org/io-uring/new.atom", - "https://lore.kernel.org/linux-sgx/new.atom", - ] - - TG_CHAT_IDS = [ - "kiizuah" - ] - - def __init__(self, client: DaemonClient, sched: AsyncIOScheduler, scraper: Scraper, mutexes: BotMutexes, conn): self.client = client @@ -55,7 +45,7 @@ class Bot(): async def __run(self): print("[__run]: Running...") - for url in self.ATOM_URLS: + for url in self.db.get_atom_urls(): try: await self.__handle_atom_url(url) except: @@ -80,10 +70,11 @@ class Bot(): async def __handle_mail(self, url, mail): - for tg_chat_id in self.TG_CHAT_IDS: + chats = self.db.get_broadcast_chats() + for chat in chats: async with self.mutexes.send_to_tg: should_wait = await self.__send_to_tg(url, mail, - tg_chat_id) + chat[1]) if should_wait: await asyncio.sleep(1) diff --git a/daemon/scraper/db.py b/daemon/scraper/db.py index a79f041..321661f 100644 --- a/daemon/scraper/db.py +++ b/daemon/scraper/db.py @@ -112,3 +112,24 @@ class Db(): return None return res[0] + + + def get_atom_urls(self): + q = """ + SELECT atom_urls.url + FROM atom_urls + """ + self.cur.execute(q) + urls = self.cur.fetchall() + + return [u[0] for u in urls] + + + def get_broadcast_chats(self): + q = """ + SELECT * + FROM broadcast_chats + """ + self.cur.execute(q) + + return self.cur.fetchall() -- Muhammad Rizki