upload, save request order buig fixed

This commit is contained in:
Your Name 2021-12-29 13:05:45 +00:00
parent 9cdc35e612
commit 091920776a
3 changed files with 67 additions and 38 deletions

View File

@ -22,12 +22,13 @@ import copy
#stock_ticker = StockTicker()
#print('API CALLER NOT STARTED')
open('log.txt', 'w').close() #wipe logs
#open('log.txt', 'w').close() #wipe logs
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
api_caller.sendline('A')
displaying_screensaver = False
uploading = False
screensaver_p = None
professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional"
@ -35,7 +36,7 @@ command = 300
tickerList = 0
DelayTime = 20
LastCommand = ''
speedTime = 25
speedTime = 25 #print('save')
LOGO_FOLDER = 'logos/'
CSV_FOLDER = 'csv/new/'
@ -126,7 +127,7 @@ def index():
def save_displaying(input_settings):
#print('save')
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']
@ -181,7 +182,7 @@ def stop():
else:
screensaver_p.close()
if displaying_screensaver:
screensaver_p.close()
ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
@ -209,13 +210,19 @@ def display_format():
@app.route("/save", methods = ['PUT', 'POST', 'GET'])
def save():
print('save')
global uploading
while uploading:
print('waiting for upload')
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']
@ -231,6 +238,17 @@ def save():
save_sports_settings(input_settings)
elif feature in ['Custom GIFs', 'Custom Images']:
images = request.files
names = list(request.files.keys())
print(names)
for name in names:
print(name)
images[name].save('user_uploads/' +name)
save_image_settings(input_settings)
elif feature == 'Custom Messages':
@ -241,6 +259,9 @@ def save():
# saves files uploaded to the webpage for images and GIFs
@app.route("/upload", methods = ['PUT', 'POST', 'GET'])
def upload():
print('upload')
global uploading
uploading = True
try:
images = request.files
@ -251,6 +272,7 @@ def upload():
except Exception as e:
print(e)
uploading = False
return index()
def remove_old_uploads():

View File

@ -962,7 +962,10 @@ function getFeatureSettings() {
case 5:
s = getWeatherSettings(page);
break;
case 6:
case 6:fetch("/upload", {
method: "POST",
body: data,
});
s = getNewsSettings(page);
break;
case 7:
@ -980,44 +983,47 @@ function getFeatureSettings() {
break;
}
//send uploaded images and gifs
if (pageNum == 11) {
var data = new FormData();
for (var i = 0; i < uploaded_images.length; i++) {
data.append(uploaded_images[i].name, uploaded_images[i]);
}
fetch("/upload", {
method: "POST",
body: data,
});
} else if (pageNum == 12) {
var data = new FormData();
for (var i = 0; i < uploaded_GIFs.length; i++) {
data.append(uploaded_GIFs[i].name, uploaded_GIFs[i]);
}
fetch("/upload", {
method: "POST",
body: data,
});
}
settings = { ...settings, ...s }; // merge both sets of settings
return settings;
}
function getFiles() {
var data = new FormData();
for (var i = 0; i < uploaded_images.length; i++) {
data.append(uploaded_images[i].name, uploaded_images[i]);
console.log(uploaded_images[i].name);
}
for (var i = 0; i < uploaded_GIFs.length; i++) {
data.append(uploaded_GIFs[i].name, uploaded_GIFs[i]);
}
//return data;
fetch("/upload", {
method: "POST",
body: data,
});
}
function saveSettings() {
displaying = getDisplaying();
feature_settings = getFeatureSettings();
console.log(displaying)
let displaying = getDisplaying();
let feature_settings = getFeatureSettings();
let files = getFiles();
console.log(JSON.stringify({'displaying': displaying, 'feature_settings': feature_settings, 'files':files}));
fetch("/save", {
method: "PUT",
method: "POST",
body: JSON.stringify({'displaying': displaying, 'feature_settings': feature_settings}),
});

View File

@ -2533,7 +2533,7 @@ class StockTicker():
for i, frame in enumerate(ImageSequence.Iterator(GIF)):
frame.thumbnail((99999, 32))
f = frame
f = self.stitchImage([frame])
frames.append(f)
@ -2543,6 +2543,7 @@ class StockTicker():
except Exception as e:
print(str(e))
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
self.logf.write(str(e))
@ -2551,7 +2552,7 @@ class StockTicker():
self.logf.write('. type: ' + str(exc_type))
self.logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
self.logf.write(str(GIFs))
#below code stitches title and GIF together
'''