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 E9ABA80908; Sun, 11 Sep 2022 10:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662892461; bh=GbzVN4L1j2zp8nK7Zvy25w7GSEVdvm5x5K42Cs9qvt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmTqT7iADDbAPWYhku6aQCqt+6YrPXYivm9N3a+uznJtzaWbeu/ysZu4xIsVSMV++ HN5cYZW/UI1jjVYNevhVgRpmaJLC3qoyHX8NF9K6+4oFFNgDyJnc5nELP0Y7mPNi1k ypI+VwTLJRVjcvZJeMMjv8aIlGetihVENP/lFwL/o/0W/gZsW4uBI7WP04GipNAAtP zTXaWaLROt93jxbY4yBdRiij+hTFPKH/tjs54m1ae2s9HXsUUQ0RUSTTO99z/l1l3z /ziLBtp/HU1uYllXGiZgnNI3Y6Y6TRiLl9eWMP/7g3VXHJETzxg3C957btUydZ4eyj OrnsnesFmjuwg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v1 17/17] [discord] Add save_email() in database insertion Date: Sun, 11 Sep 2022 17:33:23 +0700 Message-Id: <20220911103323.1949-18-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220911103323.1949-1-kiizuha@gnuweeb.org> References: <20220911103323.1949-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, 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 ignored. 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