From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
GNU/Weeb Mailing List <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>
Subject: [PATCH v3 07/18] Add insert_atom() in scraper/db.py
Date: Fri, 29 Jul 2022 08:40:41 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Add insert_atom() in scraper/db.py and call it in
packages/plugins/add_atom.py to insert atom url into the database
Signed-off-by: Muhammad Rizki <[email protected]>
---
daemon/packages/plugins/manage_atom.py | 18 +++++++++++++-----
daemon/scraper/db.py | 16 ++++++++++++++++
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/daemon/packages/plugins/manage_atom.py b/daemon/packages/plugins/manage_atom.py
index a10318f..934aba9 100644
--- a/daemon/packages/plugins/manage_atom.py
+++ b/daemon/packages/plugins/manage_atom.py
@@ -13,10 +13,18 @@ from scraper import utils
filters.chat(["kiizuah", "nekoha", -1001673279485])
)
async def add_atom_url(c: DaemonClient, m: Message):
+ if len(m.command) <= 1:
+ tutor = "Please specify the URL\n"
+ tutor += "Example: `/add_atom https://lore.kernel.org/linux-sgx/new.atom`"
+ return await m.reply(tutor)
+
text = utils.remove_command(m.text)
- if not utils.is_atom_url(text):
- return
+ is_atom = await utils.is_atom_url(text)
+ if not is_atom:
+ return await m.reply("Invalid Atom URL")
+
+ inserted = c.db.insert_atom(text)
+ if inserted is None:
+ return await m.reply(f"This URL already listened for new email.")
- ###
- ### TODO: Muhammad Rizki: Add atom url into the database
- ###
+ await m.reply(f"Success add **{text}** for listening new email")
diff --git a/daemon/scraper/db.py b/daemon/scraper/db.py
index 296559e..30ed9a7 100644
--- a/daemon/scraper/db.py
+++ b/daemon/scraper/db.py
@@ -114,6 +114,22 @@ class Db():
return res[0]
+ def insert_atom(self, atom: str):
+ try:
+ return self.__save_atom(atom)
+ except mysql.connector.errors.IntegrityError:
+ #
+ # Duplicate data, skip!
+ #
+ return None
+
+
+ def __save_atom(self, atom: str):
+ q = "INSERT INTO atom_urls (url, created_at) VALUES (%s, %s)"
+ self.cur.execute(q, (atom, datetime.utcnow()))
+ return self.cur.lastrowid
+
+
def get_atom_urls(self):
q = """
SELECT atom_urls.url
--
Muhammad Rizki
next prev parent reply other threads:[~2022-07-29 1:41 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 1:40 [PATCH v3 00/18] New feature to handle atom URLs and broadcast Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 01/18] Add new table for atom URLs and broadcast chats in db.sql Muhammad Rizki
2022-07-30 1:26 ` Ammar Faizi
2022-07-30 1:33 ` Ammar Faizi
2022-07-30 1:36 ` Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 02/18] Add ATOM_URLS and BROADCAST_CHAT methods Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 03/18] Fix MySQL InternalError: Unread result found Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 04/18] Create /add_atom command Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 05/18] Add utility functions for /add_atom Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 06/18] Refactor database methods Muhammad Rizki
2022-07-29 1:40 ` Muhammad Rizki [this message]
2022-07-29 1:40 ` [PATCH v3 08/18] Rename admin.py to debugger.py Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 09/18] Add delete_atom() function in scraper/db.py Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 10/18] Add utility function buton_numbers() Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 11/18] Move bot commands related files to packages/plugins/commands/ Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 12/18] Add del_atom callback query Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 13/18] Add insert_broadcast() in scraper/db.py Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 14/18] Add delete_broadcast() " Muhammad Rizki
2022-07-30 1:23 ` Ammar Faizi
2022-07-30 1:28 ` Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 15/18] Create /add_bc bot command Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 16/18] Add create_chat_link() function Muhammad Rizki
2022-07-30 1:22 ` Ammar Faizi
2022-07-30 1:25 ` Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 17/18] Add /del_bc bot command Muhammad Rizki
2022-07-29 1:40 ` [PATCH v3 18/18] Add del_chat callback query 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] \
[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