Compare commits

...

2 Commits

2 changed files with 27 additions and 0 deletions
+2
View File
@@ -37,6 +37,8 @@ MB_USERNAME=your-musicbrainz-username
MB_PASSWORD=your-musicbrainz-password MB_PASSWORD=your-musicbrainz-password
``` ```
The helper automatically reads `.env` from the current project directory.
## Usage ## Usage
Preview what would be submitted: Preview what would be submitted:
+25
View File
@@ -161,6 +161,30 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args() return parser.parse_args()
def load_dotenv_file(path: str = ".env") -> None:
"""Load simple KEY=VALUE pairs from a local .env file."""
if not os.path.exists(path):
return
with open(path, "r", encoding="utf-8") as env_file:
for line in env_file:
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
key = key.strip()
value = value.strip()
if not key:
continue
if (
len(value) >= 2
and value[0] == value[-1]
and value[0] in {"'", '"'}
):
value = value[1:-1]
os.environ.setdefault(key, value)
def normalize_text(value: str | None) -> str: def normalize_text(value: str | None) -> str:
return " ".join((value or "").strip().lower().split()) return " ".join((value or "").strip().lower().split())
@@ -1058,6 +1082,7 @@ def flush_and_count(
def main() -> int: def main() -> int:
args = parse_args() args = parse_args()
load_dotenv_file()
# Start time for run duration reporting # Start time for run duration reporting
start_time = time.time() start_time = time.time()