Added loading api params from dotenv file

This commit is contained in:
counterweight 2023-08-02 19:42:43 +02:00
parent fc7e6665a0
commit 819707af10
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 32 additions and 2 deletions

4
.env-example Normal file
View file

@ -0,0 +1,4 @@
URL="https://camisatoshi.com"
CONSUMER_KEY=
CONSUMER_SECRET=
VERSION="wc/v3"

View file

@ -1,4 +1,15 @@
from pathlib import Path
from dotenv import dotenv_values
from woocommerce import API
API_CONFIG = dotenv_values(
dotenv_path=Path.home() / Path(".camisatoshi-wordpress-reports/.env")
)
def check_health(url: str): def check_health(url: str):
print( print(
f"Ehem... Yeah... so... I've definitely checked {url}... I just don't remember clearly if it was alive or what..." f"Ehem... Yeah... so... I've definitely checked {url}... I just don't remember clearly if it was alive or what..."
) )
print(Path("~/.camisatoshi-wordpress-reports/.env"))
print(f"By the way, I found this: {API_CONFIG}")

16
poetry.lock generated
View file

@ -180,6 +180,20 @@ files = [
[package.extras] [package.extras]
plugins = ["importlib-metadata"] plugins = ["importlib-metadata"]
[[package]]
name = "python-dotenv"
version = "1.0.0"
description = "Read key-value pairs from a .env file and set them as environment variables"
optional = false
python-versions = ">=3.8"
files = [
{file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"},
{file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"},
]
[package.extras]
cli = ["click (>=5.0)"]
[[package]] [[package]]
name = "requests" name = "requests"
version = "2.31.0" version = "2.31.0"
@ -299,4 +313,4 @@ requests = "*"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.9" python-versions = "^3.9"
content-hash = "0f8df4840c70ba46322e889c77e4b666992ff139a1062b02bbc8e1cbeb08170c" content-hash = "16cb9a31aa761e5db7078878202ae58dfed0eac3ade16c08698e2c94855ca74c"

View file

@ -13,6 +13,7 @@ camisatoshi-wordpress-reports = "camisatoshi_wordpress_reports.cli:app"
python = "^3.9" python = "^3.9"
typer = {extras = ["all"], version = "^0.9.0"} typer = {extras = ["all"], version = "^0.9.0"}
woocommerce = "^3.0.0" woocommerce = "^3.0.0"
python-dotenv = "^1.0.0"
[build-system] [build-system]