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 5EFFB8060C; Tue, 20 Sep 2022 13:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663681740; bh=FCY6tygJHqO1A4RZninD0nKsDRmM39nrer06DJcWhAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jw1K2Qu6zseC9qRfcKiR/J/Y9H8gMZgFOr7AJkiurOVD25JkJJ+2U5sw54JZNVwuH YIaJT1IS9CP2JkwpBK/dFOKVLnWbdcARg3FXTmOHuUF7T9ioYk6qi5Dy6nJ1eQbTSf nY9PtqGr9Y7RYgOEoHmySOWfpz6NGvCxHH91qi3p7hrogQhrSXrWYpExlAQD5Zf33v q/4QXMvYu9bCGAfjo04GBKIzHtzP5/hqEWzh7FVGiempp45Eoo0BfztreG2JTf/yET +mQYGAr5wRdAU1f8zQfZpZBqEkRbQep7D8QdJxyWBK2c+n+sHFSsO5ynFUZbSZQph2 u8dnX/UZ9hDSw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v4 14/17] discord: Add save_atom() in database insertion Date: Tue, 20 Sep 2022 20:48:09 +0700 Message-Id: <20220920134812.331-15-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_atom() to save 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