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 A3D8D80DEB; Tue, 13 Sep 2022 10:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663064788; bh=vUA9rQe+6YEmETQ0w8M2Uxl7jBVIF7rYbd3Su5EuDxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZB3DeZ4Wq4ryGNU50JujBsLTf5ElOhg7SdC3qFtsKKR5AaNtYFqNHNa8h7URo5QK8 iPFeRiWOuBlA9zPeHW84HL3wSsSnrjLYIRgCv+vVd5aYI8JuEK/cSadXhZrbz8sqJD QuM8ob3f2noryASxC3WEFdegiV6tEOD4sDpKZy6UEwAVeK48VMxF0rA2FMo92C9Mdo ASlH/PGNJmJvJ6Ae8ZFUFpIXqsqgwq3CEsgemFO93bz+/mP/1xuX+tQbt4fptpRyyA Ooepvc9o9EDhxx7WyOKisW2uo+xh5/QF2NkjXfNomx2tmLt+8mAu5jDBJLDAV2bjWc ++7dt6p8gLGHA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v2 14/17] discord: Add save_atom() in database insertion Date: Tue, 13 Sep 2022 17:24:55 +0700 Message-Id: <20220913102458.615-15-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220913102458.615-1-kiizuha@gnuweeb.org> References: <20220913102458.615-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add save_atom() for saving atom url 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