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() #stock_ticker = StockTicker()
#print('API CALLER NOT STARTED') #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 = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
api_caller.sendline('A') api_caller.sendline('A')
displaying_screensaver = False displaying_screensaver = False
uploading = False
screensaver_p = None screensaver_p = None
professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional" professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional"
@@ -35,7 +36,7 @@ command = 300
tickerList = 0 tickerList = 0
DelayTime = 20 DelayTime = 20
LastCommand = '' LastCommand = ''
speedTime = 25 speedTime = 25 #print('save')
LOGO_FOLDER = 'logos/' LOGO_FOLDER = 'logos/'
CSV_FOLDER = 'csv/new/' CSV_FOLDER = 'csv/new/'
@@ -126,7 +127,7 @@ def index():
def save_displaying(input_settings): def save_displaying(input_settings):
#print('save')
all_settings = ['Stocks', 'Crypto', 'Forex', 'Current Weather', 'Daily Forecast', 'News', 'Sports (Upcoming Games)', 'Sports (Past Games)', 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'] 'Sports (Live Games)', 'Sports (Team Stats)', 'Custom Images', 'Custom GIFs', 'Custom Messages']
@@ -209,12 +210,18 @@ def display_format():
@app.route("/save", methods = ['PUT', 'POST', 'GET']) @app.route("/save", methods = ['PUT', 'POST', 'GET'])
def save(): def save():
print('save')
global uploading
while uploading:
print('waiting for upload')
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)
save_displaying(input_settings['displaying']) save_displaying(input_settings['displaying'])
@@ -231,6 +238,17 @@ def save():
save_sports_settings(input_settings) save_sports_settings(input_settings)
elif feature in ['Custom GIFs', 'Custom Images']: 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) save_image_settings(input_settings)
elif feature == 'Custom Messages': elif feature == 'Custom Messages':
@@ -241,6 +259,9 @@ def save():
# saves files uploaded to the webpage for images and GIFs # saves files uploaded to the webpage for images and GIFs
@app.route("/upload", methods = ['PUT', 'POST', 'GET']) @app.route("/upload", methods = ['PUT', 'POST', 'GET'])
def upload(): def upload():
print('upload')
global uploading
uploading = True
try: try:
images = request.files images = request.files
@@ -251,6 +272,7 @@ def upload():
except Exception as e: except Exception as e:
print(e) print(e)
uploading = False
return index() return index()
def remove_old_uploads(): def remove_old_uploads():

View File

@@ -962,7 +962,10 @@ function getFeatureSettings() {
case 5: case 5:
s = getWeatherSettings(page); s = getWeatherSettings(page);
break; break;
case 6: case 6:fetch("/upload", {
method: "POST",
body: data,
});
s = getNewsSettings(page); s = getNewsSettings(page);
break; break;
case 7: case 7:
@@ -980,44 +983,47 @@ function getFeatureSettings() {
break; 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 settings = { ...settings, ...s }; // merge both sets of settings
return 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() { function saveSettings() {
displaying = getDisplaying(); let displaying = getDisplaying();
feature_settings = getFeatureSettings(); let feature_settings = getFeatureSettings();
console.log(displaying) let files = getFiles();
console.log(JSON.stringify({'displaying': displaying, 'feature_settings': feature_settings, 'files':files}));
fetch("/save", { fetch("/save", {
method: "PUT", method: "POST",
body: JSON.stringify({'displaying': displaying, 'feature_settings': feature_settings}), 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)): for i, frame in enumerate(ImageSequence.Iterator(GIF)):
frame.thumbnail((99999, 32)) frame.thumbnail((99999, 32))
f = frame f = self.stitchImage([frame])
frames.append(f) frames.append(f)
@@ -2543,6 +2543,7 @@ class StockTicker():
except Exception as e: except Exception as e:
print(str(e))
exc_type, exc_obj, exc_tb = sys.exc_info() exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
self.logf.write(str(e)) self.logf.write(str(e))
@@ -2551,7 +2552,7 @@ class StockTicker():
self.logf.write('. type: ' + str(exc_type)) 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('\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 #below code stitches title and GIF together
''' '''