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 16DA780D4E; Mon, 19 Sep 2022 07:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663572461; bh=weJk+iqNzVFg5puJroqUQNUfz6EHt/L2OKQZisFuy9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LePF6O/8I7pAamlGNLCFIAVofUL0yZv5L1QF23yjPsKgTNzHgBKP7rhnQ2b6yDrQW AfsFxt9QCbyHPVaP7zb65bRJA+wTncaCVMUECr3Yx5Pvs5nGvrGKyg9b3Z3EXVfoHQ HYA/7CyrVYChkf58Qv/OXdoB1TdNOr/iv6K8IgUnWYrov/Gv2jIsUnqHwUGZoy84C1 GmvU/rcXcfk/wh2x/bQtz4y5nIkuiStZL73qeAGNfOSOMz6N0Uye2m3DNF2iR9I0/d L9GVSJvQDonyoCfu+QCG27sp8GuIfjE1iR1ovgYH/ySwZ8HkhngP03sUG3IlnrEx8J Kti3DIDoaFdOg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v3 17/17] discord: Add save_email() in database insertion Date: Mon, 19 Sep 2022 14:26:41 +0700 Message-Id: <20220919072641.996-18-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220919072641.996-1-kiizuha@gnuweeb.org> References: <20220919072641.996-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