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 7F3B77E328; Fri, 29 Jul 2022 00:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055326; bh=csV4IgpcwsmtfrkTGLCHmzQUWtSayhhcIdjtFPoNbB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HtB1qUK5tXe1MIU2+65E7lIYmxTx7womJIFIBtdoYy2iVfkegGBQUQWaJjqXqfR/L AhnbHRGZ0WDqLdJ9I3YGkBkfEnEjPGj+yA3I5BF+umEFeWQQjObqjGsDKw5vWSzJkD WPNsZfq9AD2Ak5VluM0QUcsGCEGIZFZSJ9lztQEEH6+BfLIKsNQtVzM+yDJF1kJ+sA Pkvn4g8wA34wVAXTBm5KuvO7dAezd3dt8KIrCNRhDApFCo+QWJw+8XQlTYxIRJ4xza JqBTHW9Id5GpUudKMuwdkN4VnnPF7lI8PDjPPutnBkQ22JPifeAlFzB5aH9Tf7K2FG bor2jc3wR9pUQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 02/18] Add ATOM_URLS and BROADCAST_CHAT methods Date: Fri, 29 Jul 2022 07:40:30 +0700 Message-Id: <20220729004046.1890-22-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: 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