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 0725F80D4E; Mon, 19 Sep 2022 07:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663572454; bh=vUA9rQe+6YEmETQ0w8M2Uxl7jBVIF7rYbd3Su5EuDxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M7D8UqVXkhNzkLDGc4GRtrSEGVzu0JuNE1FWGI7MxsmsZRoVfgLRdNgGLY3aPQ9K6 LzU6YEJyffQ3QJoCP2bH1sCWJT/eKy7C+Vh6XRl2sJ5SJoVralxlr5cwD8gKe9/4+i P3fQh/adkwC1fYf71Odjip+r47qvqx9UKDxq7QJxJqc+eOKHACZ5UmtJsAXuzWEUxy kYjDUcBvOwnHeUk1VVavwsSkx+CvIMND6Rt0ZHfDAAChXqoP0cEKuUqdbUa5QWS3b4 bgbS/Vv99fM2h5NJ2PcwkuN68TJJJMK5wYoOdCo57asJ9LhI9GI5Y5OD6n4sSSUo9N 0F95wKOnYcEiQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v3 14/17] discord: Add save_atom() in database insertion Date: Mon, 19 Sep 2022 14:26:38 +0700 Message-Id: <20220919072641.996-15-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_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