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=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from [192.168.1.2] (unknown [101.128.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id 547D57E24F; Sat, 24 Dec 2022 22:57:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671922680; bh=/lgK+IR/hNZLP3tl54yI8GV83W8Lx5pOqLr5ocIKadw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=GGAFDx12i1/zPdx0JJNPSOFbElxsir+PrySr3J5UOQDlnR1ZE+nhzGgsQ1TxnGUxV So1D+WzESmUbPF3/LBIEKH9yCd/SAWBQTT4iruhCh1JWHjlflRaxoj5MfJt+FI3Ans 6KtPIhDzBs0JDcL2xZFqdEI4PLBwKrV9adD4TOI0BZco4+pjKEvjYJ2uIsT32YqQX7 B+pvIJ1TjgiB7F3m1pY/nJ2ievA47BqBGDJgAf6lK50pJhCGxoFd3IXuIC7YECmW6Q cSE6FupuMNV/XD18JKbgLkZecgWyA2zbePJ2hw21+pvvBtrq3D9ztAbswwFm6TY073 jTdVo1J14F+rw== Message-ID: Date: Sun, 25 Dec 2022 05:57:55 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v1 2/2] Allow custom MySQL port from the env file Content-Language: en-US To: Ammar Faizi , GNU/Weeb Mailing List Cc: Alviro Iskandar Setiawan References: <20221224220008.258335-1-ammarfaizi2@gnuweeb.org> <20221224220008.258335-3-ammarfaizi2@gnuweeb.org> From: Muhammad Rizki In-Reply-To: <20221224220008.258335-3-ammarfaizi2@gnuweeb.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: On 25/12/2022 05.00, Ammar Faizi wrote: > From: Ammar Faizi > > I don't always use 3306 as the MySQL server port. Allow custom port > to be configured from the env file! > > Signed-off-by: Ammar Faizi > --- > > + 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, > password=os.getenv("DB_PASS"), > database=os.getenv("DB_NAME") > ), This code can be shorten to: client = GWClient( db_conn=connector.connect( host=os.getenv("DB_HOST"), user=os.getenv("DB_USER"), port=int(os.environ.get("DB_PORT", 3306)), password=os.getenv("DB_PASS"), database=os.getenv("DB_NAME") ) `os.environ` here is a dict object, a dict object has a .get() function, the second argument of the .get() is a default return if the first argument (dict key) is not exist. Like, DB_PORT is not exist in dict keys, then it will return 3306. > > + port = os.getenv("DB_PORT") > + if not port: > + port = 3306 > + else: > + port = int(port) > + > client = DaemonClient( > "telegram/storage/EmailScraper", > api_id=int(os.getenv("API_ID")), > @@ -30,6 +36,7 @@ def main(): > conn=connector.connect( > host=os.getenv("DB_HOST"), > user=os.getenv("DB_USER"), > + port=port, > password=os.getenv("DB_PASS"), > database=os.getenv("DB_NAME") > ), Implement this too.