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 8E6458060C; Tue, 20 Sep 2022 13:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663681743; bh=TQ/+VsiYieGTnL0y7QYT2oqXfM1Au6OBgMxQmppuhL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqUCT5Ig45kHrbGf0EmDeLwYWO68VIU9afN6M0PwbK5GlpT/ENelwaZWEMmSdd7iq X9tQZyuVTAiYjn4YCEaGTeRQ2St/AUJGXuBeEn9hjGvRf5prsp/83YSJOBMn4Ztmgn I6wnGf2nTJwbfr5/UwYviysdxU0A8ZKvjauCsucaRA9BeLoANnpBzgn/2QveRTkyAC H7cGTffSj4hsyPHaGDfuE+0E6yTD5uqVrV6xT87d6AtEaBHBXOAcGjqcFl2oAUraIT WH3JXEImuBXbFjDMvN/yVSA3t74NycodrFCI3uk5Fzxd3TWPNsqJRv4JufRnO/IGrs oMQV2uTn0NnKA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v4 15/17] discord: Add save_broadcast() in database insertion Date: Tue, 20 Sep 2022 20:48:10 +0700 Message-Id: <20220920134812.331-16-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_broadcast() to save discord guild channel to the database for send new lore emails to the channels. Signed-off-by: Muhammad Rizki --- .../database/methods/insertion/__init__.py | 4 +- .../methods/insertion/insert_broadcast.py | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 daemon/dscord/database/methods/insertion/insert_broadcast.py diff --git a/daemon/dscord/database/methods/insertion/__init__.py b/daemon/dscord/database/methods/insertion/__init__.py index 632aa55..4192735 100644 --- a/daemon/dscord/database/methods/insertion/__init__.py +++ b/daemon/dscord/database/methods/insertion/__init__.py @@ -5,8 +5,10 @@ from .insert_atom import InsertAtom +from .insert_broadcast import InsertBroadcast class Insertion( - InsertAtom + InsertAtom, + InsertBroadcast ): pass diff --git a/daemon/dscord/database/methods/insertion/insert_broadcast.py b/daemon/dscord/database/methods/insertion/insert_broadcast.py new file mode 100644 index 0000000..e68f9b4 --- /dev/null +++ b/daemon/dscord/database/methods/insertion/insert_broadcast.py @@ -0,0 +1,42 @@ +from mysql.connector import errors +from datetime import datetime + + +class InsertBroadcast: + + def save_broadcast( + self, + guild_id: int, + channel_id: int, + channel_name: str, + channel_link: str = None, + ): + try: + return self.__insert_broadcast( + guild_id=guild_id, + channel_id=channel_id, + channel_name=channel_name, + channel_link=channel_link + ) + except errors.IntegrityError: + # + # Duplicate data, skip! + # + return None + + + def __insert_broadcast( + self, + guild_id: int, + channel_id: int, + channel_name: str, + channel_link: str = None, + ): + q = """ + INSERT INTO dc_broadcasts + (guild_id, channel_id, channel_name, channel_link, created_at) + VALUES (%s, %s, %s, %s, %s) + """ + values = (guild_id, channel_id, channel_name, channel_link, datetime.utcnow()) + self.cur.execute(q, values) + return self.cur.lastrowid -- Muhammad Rizki