From 2171d2fdb950401164239d77a203209a04886894 Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 7 Jul 2023 23:22:10 +0800 Subject: [PATCH] update selected custom msg with any changes made --- server.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server.py b/server.py index bf65ce1..38ca074 100755 --- a/server.py +++ b/server.py @@ -1526,6 +1526,7 @@ def fetch_custom_msg(): data = {"feature": "Custom Messages", "speed": "medium", "speed2": "medium", "animation": "down", "title": False, "messages": [{"name": "welcome", "text": "Welcome to Fintic!", "text_colour": "White", "size": "Large", "background_colour": "Black"}, {"name": "get_started", "text": "To get started, connect your device to the \"Fintic Hotspot\" and access \"fintic.local:1024\" on your web browser. You can connect your ticker to Wi-Fi there.", "text_colour": "White", "size": "Small", "background_colour": "Black"}]} for i, each in enumerate(data['messages']): if each['name'] == value2: + the_info = {'index': i, 'text': data['messages'][i]['text'], 'name': data['messages'][i]['name'], 'size':data['messages'][i]['size'], 'text_colour': data['messages'][i]['text_colour'], 'background_colour': data['messages'][i]['background_colour']} the_info = data['messages'][i] break else: @@ -1552,6 +1553,31 @@ def sendMsgToJSON(): return index() +@app.route("/updateSelectedMsg", methods=["PUT", "POST"]) +def updateSelectedMsg(): + value = request.data.decode('utf-8') + value2 = json.loads(value) + try: + with open("csv/message_settings.json") as f: + data = json.load(f) + except: + data = {"feature": "Custom Messages", "speed": "medium", "speed2": "medium", "animation": "down", "title": False, "messages": [{"name": "welcome", "text": "Welcome to Fintic!", "text_colour": "White", "size": "Large", "background_colour": "Black"}, {"name": "get_started", "text": "To get started, connect your device to the \"Fintic Hotspot\" and access \"fintic.local:1024\" on your web browser. You can connect your ticker to Wi-Fi there.", "text_colour": "White", "size": "Small", "background_colour": "Black"}]} + try: + data['messages'][value2['index']]['name'] = value2['name'] + data['messages'][value2['index']]['text'] = value2['text'] + data['messages'][value2['index']]['text_colour'] = value2['text_colour'] + data['messages'][value2['index']]['size'] = value2['size'] + data['messages'][value2['index']]['background_colour'] = value2['background_colour'] + with open('csv/message_settings.json', 'w') as f: + json.dump(data, f) + except: + pass + + return index() + + + + if __name__ == "__main__": app.run(host='0.0.0.0', port=1024, debug=False) # the debuggger causes flickering