support dotenv file

This commit is contained in:
Karl Hudgell 2024-09-19 11:43:33 +01:00
parent 5bdfdb0881
commit 0ad1f4f8ad
4 changed files with 22 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.vscode/launch.json .vscode/launch.json
**/*.pyc **/*.pyc
.env

View File

@ -1,8 +1,11 @@
import os import os
import sys import sys
import json import json
from dotenv import load_dotenv
from lib.mqtt import create_client, update_disc, control_player, create_config from lib.mqtt import create_client, update_disc, control_player, create_config
load_dotenv()
# Define the MQTT server details # Define the MQTT server details
broker = os.environ.get("broker") broker = os.environ.get("broker")
port = int(os.environ.get("port")) port = int(os.environ.get("port"))
@ -30,4 +33,5 @@ else:
print("No JSON argument passed, running default control_player action.") print("No JSON argument passed, running default control_player action.")
# You can still have the default behavior if no JSON is passed # You can still have the default behavior if no JSON is passed
control_player(client, "EJECT") # control_player(client, "EJECT")

16
poetry.lock generated
View File

@ -14,7 +14,21 @@ files = [
[package.extras] [package.extras]
proxy = ["pysocks"] proxy = ["pysocks"]
[[package]]
name = "python-dotenv"
version = "1.0.1"
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.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca"},
{file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"},
]
[package.extras]
cli = ["click (>=5.0)"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.8" python-versions = "^3.8"
content-hash = "6c033a93847eceeaa0c39046b8cf5ddd3b31e00b768adae8c60d059d3003b2f5" content-hash = "a464e018da3c243fd5b889dddee79b9f4d25f520855325f8478224b55eebbbcc"

View File

@ -8,6 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.8" python = "^3.8"
paho-mqtt = "^2.1.0" paho-mqtt = "^2.1.0"
python-dotenv = "^1.0.1"
[build-system] [build-system]