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.157]) by gnuweeb.org (Postfix) with ESMTPSA id 619C67E257; Sat, 30 Jul 2022 04:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659156064; bh=xX8CbV6K7VeQOpO7S70lpJX3z8VEYFTSqZTPG9X7ErE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rnTlAiK24Zn51AG4kwQbThVBTmD0V2meEGgn53d7S/eKvQhj46MJf/duyJd5KLAvy cj3ONphM/KP4L9JcH40MbQ5Q/eXIZQiDEs7ikGOr6HCCfJbgFpCNG7m4HVOrFpffc7 9/kFvmfEUNVC77Puf3zNKgdFs7eAMAf9Sd9daApatThcpdz/bECLZHn/sTpUvG6lT9 kEV3WxBNsqDeYjbru66+djjjUln8/e4vMOw9KMhWS5CkRfMcZkkVeyVclnGdw7L8ZK eXeVua1fMXJ35lB4EXhZL8H2TxLYpZAr4DSGUTZ9E97v/TdxYw6o8K4L35Y6ylwudq 6twRtEPGERYPg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v4 13/18] Add insert_broadcast() in scraper/db.py Date: Sat, 30 Jul 2022 11:40:11 +0700 Message-Id: <20220730044016.988-14-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220730044016.988-1-kiizuha@gnuweeb.org> References: <20220730044016.988-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..a0f8d15 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: int, + 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: int, + 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