From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>
Subject: Re: [PATCH v1 2/2] Allow custom MySQL port from the env file
Date: Sun, 25 Dec 2022 05:57:55 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 25/12/2022 05.00, Ammar Faizi wrote:
> From: Ammar Faizi <[email protected]>
>
> 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 <[email protected]>
> ---
>
> + 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.
next prev parent reply other threads:[~2022-12-24 22:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-24 22:00 [PATCH v1 0/2] A bug fix and allow custom MySQL port Ammar Faizi
2022-12-24 22:00 ` [PATCH v1 1/2] telegram: listener: Fix missing MySQL error recovery function Ammar Faizi
2022-12-24 22:59 ` Muhammad Rizki
2022-12-24 22:00 ` [PATCH v1 2/2] Allow custom MySQL port from the env file Ammar Faizi
2022-12-24 22:57 ` Muhammad Rizki [this message]
2022-12-24 22:59 ` Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox