From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v1 02/18] Add ATOM_URLS and BROADCAST_CHAT methods
Date: Wed, 27 Jul 2022 09:46:18 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
---
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
next prev parent reply other threads:[~2022-07-27 2:46 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-27 2:46 [PATCH v1 00/18] New feature to handle atom URLs and broadcast Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 01/18] Add atom_broadcast.sql Muhammad Rizki
2022-07-27 14:45 ` Ammar Faizi
2022-07-28 5:00 ` Muhammad Rizki
2022-07-28 5:15 ` Ammar Faizi
2022-07-27 2:46 ` Muhammad Rizki [this message]
2022-07-27 2:46 ` [PATCH v1 03/18] Fix MySQL InternalError: Unread result found Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 04/18] Create /add_atom command Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 05/18] Add utility functions for /add_atom Muhammad Rizki
2022-07-27 15:09 ` Ammar Faizi
[not found] ` <[email protected]>
2022-07-28 4:06 ` Ammar Faizi
2022-08-10 22:05 ` Ammar Nofan Faizi
2022-08-11 2:41 ` Muhammad Rizki
2022-08-11 2:47 ` Ammar Nofan Faizi
2022-08-11 2:56 ` Ammar Nofan Faizi
2022-07-27 2:46 ` [PATCH v1 06/18] Refactor database methods Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 07/18] Add insert_atom() in scraper/db.py Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 08/18] Rename admin.py to debugger.py Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 09/18] Add delete_atom() function in scraper/db.py Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 10/18] Add utility function buton_numbers() Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 11/18] Move bot commands related files to packages/plugins/commands/ Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 12/18] Add del_atom callback query Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 13/18] Add insert_broadcast() in scraper/db.py Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 14/18] Add delete_broadcast() " Muhammad Rizki
2022-07-27 15:01 ` Ammar Faizi
2022-07-27 2:46 ` [PATCH v1 15/18] Create /add_bc bot command Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 16/18] Add create_chat_link() function Muhammad Rizki
2022-07-27 15:12 ` Ammar Faizi
[not found] ` <[email protected]>
2022-07-28 4:07 ` Ammar Faizi
2022-07-27 2:46 ` [PATCH v1 17/18] Add /del_bc bot command Muhammad Rizki
2022-07-27 2:46 ` [PATCH v1 18/18] Add del_chat callback query Muhammad Rizki
-- strict thread matches above, loose matches on Subject: below --
2022-07-29 0:40 [PATCH v1 00/18] New feature to handle atom URLs and broadcast Muhammad Rizki
2022-07-29 0:40 ` [PATCH v1 02/18] Add ATOM_URLS and BROADCAST_CHAT methods Muhammad Rizki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox