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 3EBCB7F937; Wed, 18 Jan 2023 17:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674064458; bh=8MoyiP9kPAN0y4wkwxUH1z6WgP+J0hBiZyh+lfQ73zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G02f2Owimz21yHvOWEgj3dPhijAYRsAsy6SmKNz7AF6FDrItAtg42kWr7QvgTQxNu RkB35BsZCNZIGVzT7zHP94owDqaperZMtnKd0pmv9ipao3eyl7ziD2vw1TmHNsiBR6 wUtNTslj4rNi2wWtnwK0lrw4IHwgJDk4+M+I3ovq0auIqVqn4HVJjJsK0vFCjmhykJ 46yKb7fqgXGGdklMkd8dMZQP8UGS1mNAY2V6QIPY/UxIvn69XaNbJ+aGuSxL6qSOBu SVE0DGe7hkYxVafjcih/GQxh1PdF0F6hNMa0qgwPNc1V0yy+7lLwRbN+ejsL93THtn IaynBmJsaskOg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 02/17] discord: Simplify code to get DB_PORT from env Date: Thu, 19 Jan 2023 00:53:41 +0700 Message-Id: <20230118175356.1853-3-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/dc.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/daemon/dc.py b/daemon/dc.py index a9d5ebd..7d34837 100644 --- a/daemon/dc.py +++ b/daemon/dc.py @@ -29,17 +29,11 @@ def main(): logger = BotLogger(Platform.DISCORD) logger.init() - port = os.getenv("DB_PORT") - if not port: - port = 3306 - else: - port = int(port) - client = GWClient( db_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