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.149]) by gnuweeb.org (Postfix) with ESMTPSA id C0E5380E1F; Sun, 25 Sep 2022 21:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664140515; bh=vD8rmwoDKpLKb6AjkhaVVSYkUVayxEus7OjXwsEb/VI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OziBK0DjImLRVFE4OxwGffcPyCK4ofCmfjGoRQOZFtiJ05Jndc1gNjYcLlVJr8nUN qgqmuq+qw/E6kuNjSxrJDMtAXgAw41VyHAeCYdonA4tPFDpvPEZJcLzRu6K6bbCu5x 6Px0HfH18cjlM5ntfXLunjjCwYw2AW7jRJR1rnn4cBD5tLC5tLxS9s3i/wcwTpsyZK m2Z9A6CIQkDcskJfa1pJiNRc0qWCvs3CBRaWXQ0cQiKp78JNXfBzAMF6SVGQ13o77Z o+qL5Q+M5bfqFwcwBp3V0NAnmkqc1QQ43gbiuU9y9JKxPqF78CMRhfgfNsx6VJI3EZ svQkfazaAJAOg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v5 14/18] discord: Add save_atom() in database insertion Date: Mon, 26 Sep 2022 04:14:23 +0700 Message-Id: <20220925211427.412-15-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220925211427.412-1-kiizuha@gnuweeb.org> References: <20220925211427.412-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add save_atom() to save the 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