remove the path for load_dotenv()
This commit is contained in:
parent
2eb8a1641b
commit
2b8c95f3f6
34
main.py
34
main.py
@ -4,19 +4,15 @@ import json
|
||||
from dotenv import load_dotenv
|
||||
from lib.mqtt import create_client, update_disc, control_player, create_config
|
||||
|
||||
|
||||
# Path to your .env file
|
||||
dotenv_path = '/home/dietpi/floppy-ytube-player/.env'
|
||||
|
||||
# Load the .env file
|
||||
load_dotenv(dotenv_path)
|
||||
load_dotenv()
|
||||
|
||||
# Define the MQTT server details
|
||||
broker = os.environ.get("broker")
|
||||
port = int(os.environ.get("port"))
|
||||
# MQTT username and password
|
||||
username = os.environ.get('username')
|
||||
password = os.environ.get('password')
|
||||
username = os.environ.get("username")
|
||||
password = os.environ.get("password")
|
||||
|
||||
print(f"Broker: {broker}, Port: {port}, Username: {username}")
|
||||
|
||||
@ -28,24 +24,20 @@ create_config(client)
|
||||
if len(sys.argv) > 1:
|
||||
# Get the JSON argument from the command line
|
||||
json_str = sys.argv[1]
|
||||
|
||||
|
||||
try:
|
||||
# Convert the JSON string into a dictionary
|
||||
disc_data = json.loads(json_str)
|
||||
# Pass the parsed data to the update_disc function
|
||||
update_disc(client, disc_data)
|
||||
except json.JSONDecodeError as e:
|
||||
try:
|
||||
if json_str == "EJECT":
|
||||
control_player(client, "EJECT")
|
||||
update_disc(client, {"type":"album", "id":"EJECT"})
|
||||
elif json_str == "PLAY":
|
||||
control_player(client, "PLAY")
|
||||
except Exception:
|
||||
print(f"Invalid JSON format: {e}")
|
||||
try:
|
||||
if json_str == "EJECT":
|
||||
control_player(client, "EJECT")
|
||||
update_disc(client, {"type": "album", "id": "EJECT"})
|
||||
elif json_str == "PLAY":
|
||||
control_player(client, "PLAY")
|
||||
except Exception:
|
||||
print(f"Invalid JSON format: {e}")
|
||||
else:
|
||||
print("No JSON argument passed, running default control_player action.")
|
||||
|
||||
# You can still have the default behavior if no JSON is passed
|
||||
# control_player(client, "EJECT")
|
||||
|
||||
print("No JSON argument passed, running default control_player action.")
|
Loading…
x
Reference in New Issue
Block a user