Added correct env path import

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-05 10:12:49 +02:00
parent dfbc840c69
commit 35bfeeb51e
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
2 changed files with 13 additions and 2 deletions

14
main.py
View File

@ -22,6 +22,16 @@ import argparse
import subprocess import subprocess
import sys import sys
import os import os
from dotenv import load_dotenv
from pathlib import Path
# Always load .env from the script's directory
dotenv_path = Path(__file__).resolve().parent / ".env"
if dotenv_path.exists():
load_dotenv(dotenv_path)
else:
print(f"⚠️ Warning: No .env file found at {dotenv_path}")
PORT = int(os.getenv("PORT", 5000)) PORT = int(os.getenv("PORT", 5000))
def run_command(command, dry_run=False): def run_command(command, dry_run=False):
@ -195,7 +205,7 @@ def browse(args):
This command launches the Chromium browser to view the running application. This command launches the Chromium browser to view the running application.
""" """
command = ["chromium", "http://localhost:5000"] command = ["chromium", f"http://localhost:{PORT}"]
run_command(command, args.dry_run) run_command(command, args.dry_run)
@ -223,7 +233,7 @@ def main():
# Browse command # Browse command
parser_browse = subparsers.add_parser( parser_browse = subparsers.add_parser(
"browse", help="Open http://localhost:5000 in Chromium browser." "browse", help="Open application in Chromium browser."
) )
parser_browse.set_defaults(func=browse) parser_browse.set_defaults(func=browse)

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
python-dotenv