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 E63F88060C; Tue, 20 Sep 2022 13:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663681747; bh=weJk+iqNzVFg5puJroqUQNUfz6EHt/L2OKQZisFuy9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WaZ37N2gD2niZ0KJSvgADe1+CrleyRn6PfFeKSrFU50ya9OxOcNsmTAxeTqMy5oUh FhX108F3gaad6rZZbxOgWEKAXz2dRibL+Fr5r7JcDZRKN2BNWSx7nUIdAh8iAh849/ payMQdl70KYoqPS0ELkPx3Lbr23FuLTx+EFWoXypEcBVBeR+c/Hj7xdqfA+8+QWmqr 84SfMrc8EKEmSi9QX4BmRhUSakeqmp9z7hcLBC7C9yYXW9Eu6rYn+/GnEY/vQV/87a BQyJh2BlMUz7yHDYCkCfHnpZuTZ4OuSItZDeKdP4NkJ9/MtySjjjYG0I+JWo7qfS4I T77S7RvCdx+nQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v4 17/17] discord: Add save_email() in database insertion Date: Tue, 20 Sep 2022 20:48:12 +0700 Message-Id: <20220920134812.331-18-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220920134812.331-1-kiizuha@gnuweeb.org> References: <20220920134812.331-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