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.94]) by gnuweeb.org (Postfix) with ESMTPSA id D7A047FA25; Wed, 27 Jul 2022 02:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658890041; bh=72sTS90LwFLaMwFjJ5AnEDPGSPKIpteYCNI7bqcAMgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H22pFKGBr4TttTekqYqR7W8eHD51Aa/6bxV/Ah8oyxXhwJDsfD2n1QxYPhSdPKK05 OrQwTqHhi1Utrx30sWjWQl8I67wCshDSfK0y1RgjgSAn/pC6qfnMaisCRNpXyjXda7 GZcjUF2iX7GVQy5G4u2/74XpufrJWMrUfiiuXIvSbTX+Au9GEVDmHFNCQes9Slqbcn C/eOISRyrVQKh92SngLFkkvb0nLSLn//qzJN+NkhuanmxO7ElKl6JNsQ0IZAFI5yjR We4wHGT0vP0gmkIH41Mhj5sr4d/sAGyA5nCBBmLWv8P36HqwIH8z5+5AqqrS5sUgql whjnzI0LNP0AA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v1 13/18] Add insert_broadcast() in scraper/db.py Date: Wed, 27 Jul 2022 09:46:29 +0700 Message-Id: <20220727024634.1995-14-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220727024634.1995-1-kiizuha@gnuweeb.org> References: <20220727024634.1995-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add insert_broadcast() in scraper/db.py to insert the chat room for receiving new email into the database. Signed-off-by: Muhammad Rizki --- daemon/scraper/db.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/daemon/scraper/db.py b/daemon/scraper/db.py index 24fc2c6..805b591 100644 --- a/daemon/scraper/db.py +++ b/daemon/scraper/db.py @@ -5,6 +5,7 @@ # from datetime import datetime +from typing import Union import mysql @@ -153,6 +154,51 @@ class Db(): return [u[0] for u in urls] + def insert_broadcast( + self, + chat_id: Union[int, str], + name: str, + type: str, + created_at: "datetime", + username: str = None, + link: str = None, + ): + try: + return self.__save_broadcast( + chat_id=chat_id, + name=name, + type=type, + created_at=created_at, + username=username, + link=link + ) + except mysql.connector.errors.IntegrityError: + # + # Duplicate data, skip! + # + return None + + + def __save_broadcast( + self, + chat_id: Union[int, str], + name: str, + type: str, + created_at: "datetime", + username: str = None, + link: str = None, + ): + q = """ + INSERT INTO broadcast_chats + (chat_id, username, name, type, link, created_at) + VALUES + (%s, %s, %s, %s, %s, %s) + """ + values = (chat_id, username, name, type, link, created_at) + self.cur.execute(q, values) + return self.cur.lastrowid + + def get_broadcast_chats(self): q = """ SELECT * -- Muhammad Rizki