38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import os
|
|
import sys
|
|
import json
|
|
from dotenv import load_dotenv
|
|
from lib.mqtt import create_client, update_disc, control_player, create_config
|
|
|
|
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')
|
|
|
|
client = create_client(broker, port, username, password)
|
|
|
|
create_config(client)
|
|
|
|
# Check if any arguments are passed
|
|
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:
|
|
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")
|
|
|