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 [175.158.50.43]) by gnuweeb.org (Postfix) with ESMTPSA id 165B181A0E; Wed, 18 Jan 2023 17:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674064456; bh=pOvvHKZxFaXSzcJ1aWcSR1Yo32oXxxVLCxJ4BLMGr7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PzG8wzWCSUx9nZlM87EfTz5ibR8O/zVchB/r3P1lW2tVSLzSnkImDspUdkS+Nr+Wq Pu2yA2z2WZgzK1V88nik197oJDEBvNMEwHB7Axa/tPKAkwi9hd+XdIMb5Ui9fSGNoX WNqcStNfYM3qkHTp8q7bCvZmMgixBalR3zIhN3y3JOqgu9RI2LYNLDlg0YdNqj+Txx wkzMFr+wcYSTzZSy0YXQ1Qx5jwOQMnVmGpVA6Ztjkqk+QSs2rRgEVDz26V0LldKJzE ae/MZOKGl+LqO4bdUXmIvRG9gImw82DCEn+GZRSiKfotcJxYTsOTXgsZOfb7v/Eil2 kQpe1UxGfn6Gw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 01/17] telegram: Simplify code to get DB_PORT from env Date: Thu, 19 Jan 2023 00:53:40 +0700 Message-Id: <20230118175356.1853-2-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230118175356.1853-1-kiizuha@gnuweeb.org> References: <20230118175356.1853-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Using `int(os.environ.get("DB_PORT", 3306))` is the best practice to get the DB_PORT rather than using if statement. This change simplifies the code. Signed-off-by: Muhammad Rizki --- daemon/tg.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/daemon/tg.py b/daemon/tg.py index 9f36e54..6b2ec20 100644 --- a/daemon/tg.py +++ b/daemon/tg.py @@ -22,12 +22,6 @@ def main(): logger = BotLogger() logger.init() - port = os.getenv("DB_PORT") - if not port: - port = 3306 - else: - port = int(port) - client = DaemonTelegram( "telegram/storage/EmailScraper", api_id=int(os.getenv("API_ID")), @@ -37,7 +31,7 @@ def main(): conn=connector.connect( host=os.getenv("DB_HOST"), user=os.getenv("DB_USER"), - port=port, + port=int(os.environ.get("DB_PORT", 3306)), password=os.getenv("DB_PASS"), database=os.getenv("DB_NAME") ), -- Muhammad Rizki