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 3BC2E7E328; Fri, 29 Jul 2022 00:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055349; bh=xX8CbV6K7VeQOpO7S70lpJX3z8VEYFTSqZTPG9X7ErE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HPA3+pehS/AzQTlA1ESZDdGYmqizxxZufkefL34JIPn53rGyHMdP7H5XvGXZZyHOR 3PmgH8CSZ5gi44Dpi2A02/owZWz1F/GFukAuD91LvMAgTC0xhEB2CNChGY/8d4eV11 LbY6MF1q2dVon4943ow45Go3Pk3Ahwlzm7v7iGf0SpfchWX+fz8KLJVosowBeX7PMv 71mlDHlDzj1VRHWD5TGLIFKWXC5qp8aMtfMMPstCSFUrJcVd1AQ3wvvoMlN0b5iIIk jEx8M4Vt9Hr694Jku650Y/WtrWCNOGWVC8wW2NirmFCN+XxTrO7CpF454mqX4FDeeE xmm/dfLQCZwqg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 13/18] Add insert_broadcast() in scraper/db.py Date: Fri, 29 Jul 2022 07:40:41 +0700 Message-Id: <20220729004046.1890-33-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..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