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.226]) by gnuweeb.org (Postfix) with ESMTPSA id BF14880846; Mon, 1 Aug 2022 00:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659313210; bh=xX8CbV6K7VeQOpO7S70lpJX3z8VEYFTSqZTPG9X7ErE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EXXovqV1ViFeDLcGjA7yfO+N8TCq1e5LT34kJdycitzoRFai01V8S0ZYeIshaDA9l 23IYHZio9QnHSZwuJBm7kbXf1gdZxMPG+MV7x2JlJJJ+NygXLaeWR/8QLgihK1AuCw T1CrgK0axIchuZ8BsaTN8BNRF1QaAcpro8sw8EK63lz04De/F6kfKqb4oFNQ9kOjt+ b5ErR7KQU/FK575h6Nw2EVAjudjteQJJezAXC3xAE08rEByayQ3qglkN9gXu54iUQ+ 0Fgu6W3wsyxKB7rHCKtx4OrOmr72xW9xzXDc6wJfocJeP1f26Iir43aNVot4g/gzZ6 oX1tmd8AEt5Yg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v5 14/19] Add insert_broadcast() in scraper/db.py Date: Mon, 1 Aug 2022 07:19:12 +0700 Message-Id: <20220801001917.992-15-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220801001917.992-1-kiizuha@gnuweeb.org> References: <20220801001917.992-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