This commit is contained in:
Your Name 2021-12-10 17:06:47 +00:00
parent 81293fbea7
commit 6196ead71d
2 changed files with 99 additions and 75 deletions

View File

@ -18,6 +18,7 @@ import json
from multiprocessing import Process from multiprocessing import Process
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import numpy as np import numpy as np
import copy
#stock_ticker = StockTicker() #stock_ticker = StockTicker()
#print('API CALLER NOT STARTED') #print('API CALLER NOT STARTED')
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") 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) 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']) @app.route ("/start", methods = ['PUT', 'POST'])
def start(): def start():
global displaying_screensaver global displaying_screensaver
@ -129,36 +158,6 @@ def start():
ticker = pexpect.spawn("sudo -E python3 stockTicker.py") ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
displaying_screensaver = False 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') ticker.sendline('K')
@ -202,14 +201,19 @@ def display_format():
print(professional) print(professional)
return index() return index()
@app.route("/feature_settings", methods = ['PUT', 'POST', 'GET']) @app.route("/save", methods = ['PUT', 'POST', 'GET'])
def feature_settings(): def save():
data = str(request.data.decode('utf-8')) data = str(request.data.decode('utf-8'))
input_settings = json.loads(data) input_settings = json.loads(data)
print(input_settings) print(input_settings)
save_displaying(input_settings['displaying'])
input_settings= input_settings['feature_settings']
feature = input_settings['feature'] feature = input_settings['feature']
if feature in ['Stocks', 'Crypto', 'Forex']: if feature in ['Stocks', 'Crypto', 'Forex']:
save_trade_settings(input_settings) save_trade_settings(input_settings)
@ -377,20 +381,24 @@ def screensaver():
def combine_dict(current_settings, input_symbols, current_key): 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 # 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()) current_symbols = list(current_settings[current_key].keys())
# add any stock that arent current in the settings # add any stock that arent current in the settings
for IS in input_symbols: for IS in input_symbols:
if IS not in current_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 # remove stocks not in settings
for CS in current_symbols: for CS in current_symbols:
if CS not in input_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): def save_trade_settings(input_settings):

View File

@ -794,38 +794,11 @@ allFeaturesTextAddBtn.map((value, index) => {
var startButton = document.getElementById("start-btn"); var startButton = document.getElementById("start-btn");
// start the display // start the display
startButton.addEventListener("click", () => { 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", { fetch("/start", {
method: "PUT", method: "PUT",
body: JSON.stringify(features),
}); });
}
}); });
var brightnessButton = document.getElementById("brightness-btn"); 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"); let featureSelector = document.getElementById("drop");
feature = getSelected(featureSelector); feature = getSelected(featureSelector);
@ -973,14 +979,7 @@ function saveSettings() {
s = getMessageSettings(page); s = getMessageSettings(page);
break; break;
} }
settings = { ...settings, ...s }; // merge both sets of settings
fetch("/feature_settings", {
method: "PUT",
body: JSON.stringify(settings),
});
//send uploaded images and gifs //send uploaded images and gifs
if (pageNum == 11) { if (pageNum == 11) {
var data = new FormData(); var data = new FormData();
@ -1005,11 +1004,28 @@ function saveSettings() {
body: data, body: data,
}); });
} }
settings = { ...settings, ...s }; // merge both sets of settings
return settings;
} }
let saveSettingsButtons = document
.querySelectorAll(".save-btn-div") function saveSettings() {
.forEach((button) => button.addEventListener("click", 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 // gets the stock, crypto or forex specific settings
function getTradingSettings(page) { function getTradingSettings(page) {