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.112.71]) by gnuweeb.org (Postfix) with ESMTPSA id 706CE81914; Tue, 17 Jan 2023 22:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673993563; bh=pOvvHKZxFaXSzcJ1aWcSR1Yo32oXxxVLCxJ4BLMGr7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=efeySVXQDFso6IZdsNOiJPTS/AF5fhsrhT4pgpX+Ol62M8iODpdyjtGSBrM3yLdBM 0GeEbBLId0Y2KHC7LBIYKeSy69ATBr6GvHUwmIToUtn4fCyWQRLcyA4w6j5sf1t96W TQ0bTNt72iDSDJLBipV0ILhGpuo0O53pXpK46SMcwjlqYD6yJjq3+2ZCSnOOxdV0T8 WqYn24GTSHV1TrYlIGn1vXhc09dJ6sj0Z6HsJzJuJD5vyBoxhPzORxw9a3gzwQPmCZ 3XYjU822f5/D5ppsIhVGQ77MEGYkZ9BaDlJO87cNixA+qBNIVAeXzJC8MvMhyFmRn5 xWnehCRt/7BVA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 01/15] telegram: Simplify code to get DB_PORT from env Date: Wed, 18 Jan 2023 05:12:02 +0700 Message-Id: <20230117221216.1783-2-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230117221216.1783-1-kiizuha@gnuweeb.org> References: <20230117221216.1783-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