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 E804D80631; Wed, 27 Jul 2022 02:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658890018; bh=csV4IgpcwsmtfrkTGLCHmzQUWtSayhhcIdjtFPoNbB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z88WmIgiGRN6t3T3ll52uj8CcWMJPkTExxlRkzGmN/m92lyEqXpKzxOB+oqV3hyg0 958fQIhkttssyJG+UOXh64iO3k9VdSC0y65ea5UKmOP0Y33RMPUeZbqGs1liptVqRZ a72Bo9FZz7hKRquRB5X49kZLSgUKF54BN+sghHLYubNzVn1F1guuC6zLVlSAuAkMSN wzazTkQTpVlX97WegObmsoQy8RhRW5TKKxGLrl9tTnuzOUwDrbta12hm139eRCsjjF bLp2OmfAcBakDJ9maZE/NfiFHDTrEfJ27uw52SfZs+m8wvRP2EAF97CE9d5i6BYTG7 B5lCElqcZmyKw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v1 02/18] Add ATOM_URLS and BROADCAST_CHAT methods Date: Wed, 27 Jul 2022 09:46:18 +0700 Message-Id: <20220727024634.1995-3-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220727024634.1995-1-kiizuha@gnuweeb.org> References: <20220727024634.1995-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