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.100]) by gnuweeb.org (Postfix) with ESMTPSA id 9674B80DD3; Tue, 13 Sep 2022 10:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663064795; bh=weJk+iqNzVFg5puJroqUQNUfz6EHt/L2OKQZisFuy9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XmIdQXmkXX1vTHmMJ+t25gF8EfPg2qFM/DLt0RAtTeetkJtOIwrdWv8xQggnaFfMQ k4w5oKSnX1hNU08lfVDuz49pNxNULuKNNOTclUBeWG5bhnO8r62+0fx1mdUhxEnR9x 8ARlmQCkalUTdKKdmw/Z85RRFcCukrCyKF642n3bGzUaomKnFqxm0iP2Bxhve3TtId +hLj//ueIRviFDpmvE8UX7Vt9s3sTXfzPo1UoNsrLflMhLLfIaWdRtYA3JFh0ig+/t IOwGFUdsajbOeq+r+j7BeVE9oYTeoQoPrTY3z6CI2Y5oDmevgvm/8SEuP5m+KISBNs WFt17uyACxPTg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v2 17/17] discord: Add save_email() in database insertion Date: Tue, 13 Sep 2022 17:24:58 +0700 Message-Id: <20220913102458.615-18-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220913102458.615-1-kiizuha@gnuweeb.org> References: <20220913102458.615-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add save_email() to save raw lore emails to the database. Explanation: The functionality is like save_discord_mail() but it's still differ. Save lore emails if it's not exist in database yet, if it does then ignore. Signed-off-by: Muhammad Rizki --- .../database/methods/insertion/__init__.py | 4 +++- .../methods/insertion/insert_email.py | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 daemon/dscord/database/methods/insertion/insert_email.py diff --git a/daemon/dscord/database/methods/insertion/__init__.py b/daemon/dscord/database/methods/insertion/__init__.py index dd3ecf4..5137b84 100644 --- a/daemon/dscord/database/methods/insertion/__init__.py +++ b/daemon/dscord/database/methods/insertion/__init__.py @@ -7,10 +7,12 @@ from .insert_atom import InsertAtom from .insert_broadcast import InsertBroadcast from .insert_discord import InsertDiscord +from .insert_email import InsertEmail class Insertion( InsertAtom, InsertBroadcast, - InsertDiscord + InsertDiscord, + InsertEmail ): pass diff --git a/daemon/dscord/database/methods/insertion/insert_email.py b/daemon/dscord/database/methods/insertion/insert_email.py new file mode 100644 index 0000000..0fab378 --- /dev/null +++ b/daemon/dscord/database/methods/insertion/insert_email.py @@ -0,0 +1,20 @@ +from mysql.connector import errors +from datetime import datetime + + +class InsertEmail: + + def save_email(self, email_msg_id): + try: + return self.__insert_email(email_msg_id) + except errors.IntegrityError: + # + # Duplicate data, skip! + # + return None + + + def __insert_email(self, email_msg_id): + q = "INSERT INTO dc_emails (message_id, created_at) VALUES (%s, %s)" + self.cur.execute(q, (email_msg_id, datetime.utcnow())) + return self.cur.lastrowid -- Muhammad Rizki