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 1373D80D90; Sun, 11 Sep 2022 10:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662892454; bh=28z30edxWdl3GtOCOmqoM7DQdgUlrtEx6wPcndV/udM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVE+nWirTJrl/Gim2g24uhHm1+7ahdgLqRgnCW1tbOUfD8bbCp1y7+07jj4dXsr/j twVseFfkjeirf9nCcqm7qpLBb0UNdBkf8B0JpB0OWXGN6bYioO/U6H61HIsS+E2cSr 18SpWp+VZvqC3AuvAb2YKfsFCMpkkjrnS5/jBDBi+I+AoEA134YuLBU6l6Ss0cBL9G 2n8m3JRZH99KCw/swQmcGKBY6FrykwtPXyNJOwxVZkzT3gdDiJ5H3peA/ytar7fDP9 RPnjPuzkpGZmGmvf5EDI0XexdYuWHkXvViHt+G+HIHCvd9w8wNnVVEfcC4ddE5uDvY cfY6OB6Z5zlJg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v1 14/17] [discord] Add save_atom() in database insertion Date: Sun, 11 Sep 2022 17:33:20 +0700 Message-Id: <20220911103323.1949-15-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_atom() for saving atom urls into the database. Signed-off-by: Muhammad Rizki --- daemon/dscord/database/methods/__init__.py | 12 +++++++++ .../database/methods/insertion/__init__.py | 12 +++++++++ .../database/methods/insertion/insert_atom.py | 27 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 daemon/dscord/database/methods/__init__.py create mode 100644 daemon/dscord/database/methods/insertion/__init__.py create mode 100644 daemon/dscord/database/methods/insertion/insert_atom.py diff --git a/daemon/dscord/database/methods/__init__.py b/daemon/dscord/database/methods/__init__.py new file mode 100644 index 0000000..189ec67 --- /dev/null +++ b/daemon/dscord/database/methods/__init__.py @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + + +from .insertion import Insertion + + +class DBMethods( + Insertion +): pass diff --git a/daemon/dscord/database/methods/insertion/__init__.py b/daemon/dscord/database/methods/insertion/__init__.py new file mode 100644 index 0000000..632aa55 --- /dev/null +++ b/daemon/dscord/database/methods/insertion/__init__.py @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + + +from .insert_atom import InsertAtom + + +class Insertion( + InsertAtom +): pass diff --git a/daemon/dscord/database/methods/insertion/insert_atom.py b/daemon/dscord/database/methods/insertion/insert_atom.py new file mode 100644 index 0000000..9468eca --- /dev/null +++ b/daemon/dscord/database/methods/insertion/insert_atom.py @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# Copyright (C) 2022 Ammar Faizi +# + + +from mysql.connector import errors +from datetime import datetime + + +class InsertAtom: + + def save_atom(self, atom: str): + try: + return self.__insert_atom(atom) + except errors.IntegrityError: + # + # Duplicate data, skip! + # + return None + + + def __insert_atom(self, atom: str): + q = "INSERT INTO dc_atoms (url, created_at) VALUES (%s, %s)" + self.cur.execute(q, (atom, datetime.utcnow())) + return self.cur.lastrowid -- Muhammad Rizki