rpi-rgb/app/color.py
Finn Christiansen f7ede63681
Some checks failed
CSS Linter / CSS-Lint (push) Failing after 23s
Javascript Linter / Javascript-Lint (push) Successful in 10s
Python formatting PEP8 / Pyhton-PEP8 (push) Successful in 13s
introduce blueprints and unit tests
2023-06-05 22:33:36 +02:00

27 lines
784 B
Python

from flask import Blueprint
import socket
import os
import json
color_blueprint = Blueprint('color', __name__)
@color_blueprint.route('/color/<color>', methods=['POST'])
def color(color):
socket_path = '/var/www/vhosts/rgb.local/rgb_socket'
if os.path.exists(socket_path):
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(socket_path)
client.sendall(color.encode())
client.close()
return (json.dumps({'success': True}),
200,
{'ContentType': 'application/json'})
else:
return (json.dumps({
'success': False,
'message': 'socket not found'
}),
500,
{'ContentType': 'application/json'})