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 69B46806DF; Fri, 29 Jul 2022 00:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055310; bh=72sTS90LwFLaMwFjJ5AnEDPGSPKIpteYCNI7bqcAMgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HJtbpwIhuC3YHjyjBSzuMQeWOiUhjWHaQ1IxGFJJZ+W41l9dSD1rsC9GyHbnZUX3j AHmNy23BkG8VyO8kHDqyd2InSr8guGzq/P7Qyl5hdWN7pZDzydzK5zSRLgu6g1U++F x/Sh8m78I3Bo4/obmQDJkoYUXg2nTnzSZet08i0/vOU04aAAC6CERMjw4GH/kPz6Qx PAaopou/g6/yulsJI9zUorjChYxJvg6VPFMBmZbkQamDbQhM8C4fw6GHFrniMk/zQ3 nvms5mMrUOdAYFr0ksEF58TFgpqqw14a8kNiVoK63T/YwSeRubkxJZqNdBD0xPdGLP coqBburipdQIQ== 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: Fri, 29 Jul 2022 07:40:22 +0700 Message-Id: <20220729004046.1890-14-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220729004046.1890-1-kiizuha@gnuweeb.org> References: <20220729004046.1890-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