From 6196ead71def8216a252ea040509d12306af255f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 10 Dec 2021 17:06:47 +0000 Subject: [PATCH] bugfixes --- server.py | 78 ++++++++++++++++++++++------------------- static/app.js | 96 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 99 insertions(+), 75 deletions(-) diff --git a/server.py b/server.py index 3928af4..4f6cec5 100755 --- a/server.py +++ b/server.py @@ -18,6 +18,7 @@ import json from multiprocessing import Process from subprocess import Popen, PIPE import numpy as np +import copy #stock_ticker = StockTicker() #print('API CALLER NOT STARTED') api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") @@ -118,6 +119,34 @@ def index(): return render_template('index.html', **templateData) + +def save_displaying(input_settings): + + + all_settings = ['Stocks', 'Crypto', 'Forex', 'Current Weather', 'Daily Forecast', 'News', 'Sports (Upcoming Games)', 'Sports (Past Games)', + 'Sports (Live Games)', 'Sports (Team Stats)', 'Custom Images', 'Custom GIFs', 'Custom Messages'] + + if professional: + all_settings = ['Stocks', 'Crypto', 'Forex', 'Current Weather', 'News'] + + + positions = [] + display_settings = [] + + if professional: + input_settings[0] = [i for i in input_settings[0] if i in all_settings] + input_settings[1] = [i for i in input_settings[1] if i in all_settings] + + + + s = "Professional" if professional else "Standard" + display_settings = [s] + [input_settings] + + with open('csv/display_settings.json', 'w+') as f: + json.dump(list(display_settings), f) + + + @app.route ("/start", methods = ['PUT', 'POST']) def start(): global displaying_screensaver @@ -129,36 +158,6 @@ def start(): ticker = pexpect.spawn("sudo -E python3 stockTicker.py") api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") displaying_screensaver = False - - - - data = str(request.data) - - all_settings = ['Stocks', 'Crypto', 'Forex', 'Current Weather', 'Daily Forecast', 'News', 'Sports (Upcoming Games)', 'Sports (Past Games)', - 'Sports (Live Games)', 'Sports (Team Stats)', 'Custom Images', 'Custom GIFs', 'Custom Messages'] - - if professional: - all_settings = ['Stocks', 'Crypto', 'Forex', 'Current Weather', 'News'] - - print(professional) - positions = [] - display_settings = [] - data = str(request.data.decode('utf-8')) - - input_settings = json.loads(data) - print(input_settings) - print(all_settings) - if professional: - input_settings[0] = [i for i in input_settings[0] if i in all_settings] - input_settings[1] = [i for i in input_settings[1] if i in all_settings] - - print(input_settings) - - s = "Professional" if professional else "Standard" - display_settings = [s] + [input_settings] - - with open('csv/display_settings.json', 'w+') as f: - json.dump(list(display_settings), f) ticker.sendline('K') @@ -202,14 +201,19 @@ def display_format(): print(professional) return index() -@app.route("/feature_settings", methods = ['PUT', 'POST', 'GET']) -def feature_settings(): +@app.route("/save", methods = ['PUT', 'POST', 'GET']) +def save(): data = str(request.data.decode('utf-8')) input_settings = json.loads(data) print(input_settings) + + save_displaying(input_settings['displaying']) + + input_settings= input_settings['feature_settings'] + feature = input_settings['feature'] if feature in ['Stocks', 'Crypto', 'Forex']: save_trade_settings(input_settings) @@ -377,20 +381,24 @@ def screensaver(): def combine_dict(current_settings, input_symbols, current_key): # removes keys not in input from current_settings[current_key] and adds keys not in current from input + new_settings = copy.deepcopy(current_settings) + new_settings[current_key] = {} current_symbols = list(current_settings[current_key].keys()) # add any stock that arent current in the settings for IS in input_symbols: if IS not in current_symbols: - current_settings[current_key][IS] = [] + new_settings[current_key][IS] = [] + else: + new_settings[current_key][IS] = current_settings[current_key][IS] # remove stocks not in settings for CS in current_symbols: if CS not in input_symbols: - del current_settings[current_key][CS] + del new_settings[current_key][CS] - return current_settings + return new_settings def save_trade_settings(input_settings): diff --git a/static/app.js b/static/app.js index 7618d14..752c4ff 100755 --- a/static/app.js +++ b/static/app.js @@ -794,38 +794,11 @@ allFeaturesTextAddBtn.map((value, index) => { var startButton = document.getElementById("start-btn"); // start the display startButton.addEventListener("click", () => { - - let opt = getSelected(displayFormats); - - if (opt.includes("Standard")) { - var list_el = document.getElementById("display-format"); - - let features = getListItems(list_el); - fetch("/start", { - method: "PUT", - body: JSON.stringify(features), - }); - } else if (opt.includes("Professional")) { - - var top_list_el = document.getElementById("display-format"); - - let top_features = getListItems(top_list_el); - - - var bot_list_el = document.getElementById("display-format-2"); - - let bot_features = getListItems(bot_list_el); - - - let features = [top_features, bot_features]; - fetch("/start", { method: "PUT", - body: JSON.stringify(features), }); - } }); var brightnessButton = document.getElementById("brightness-btn"); @@ -913,8 +886,41 @@ dispFormatButton.addEventListener("click", () => { }); }); -// saves the feature specific settings -function saveSettings() { + +// gets which features are to be displayed +function getDisplaying(){ + let opt = getSelected(displayFormats); + + if (opt.includes("Standard")) { + var list_el = document.getElementById("display-format"); + + let features = getListItems(list_el); + + return features; + } else if (opt.includes("Professional")) { + + var top_list_el = document.getElementById("display-format"); + + let top_features = getListItems(top_list_el); + + + var bot_list_el = document.getElementById("display-format-2"); + + let bot_features = getListItems(bot_list_el); + + + let features = [top_features, bot_features]; + + + return features; + } + +} + + +// gets feature specific settings +function getFeatureSettings() { + let featureSelector = document.getElementById("drop"); feature = getSelected(featureSelector); @@ -973,14 +979,7 @@ function saveSettings() { s = getMessageSettings(page); break; } - - settings = { ...settings, ...s }; // merge both sets of settings - - fetch("/feature_settings", { - method: "PUT", - body: JSON.stringify(settings), - }); - + //send uploaded images and gifs if (pageNum == 11) { var data = new FormData(); @@ -1005,11 +1004,28 @@ function saveSettings() { body: data, }); } + + settings = { ...settings, ...s }; // merge both sets of settings + + return settings; } -let saveSettingsButtons = document - .querySelectorAll(".save-btn-div") - .forEach((button) => button.addEventListener("click", saveSettings)); + +function saveSettings() { + + displaying = getDisplaying(); + feature_settings = getFeatureSettings(); + console.log(displaying) + fetch("/save", { + method: "PUT", + body: JSON.stringify({'displaying': displaying, 'feature_settings': feature_settings}), + }); + + +} + + +let saveSettingsButtons = document.querySelectorAll(".save-btn-div").forEach((button) => button.addEventListener("click", saveSettings)); // gets the stock, crypto or forex specific settings function getTradingSettings(page) {