uploaded images saved to Pi

This commit is contained in:
Neythen 2021-10-07 20:40:43 +01:00
parent 3fb1ee197a
commit acd46c0aef
10 changed files with 66 additions and 6 deletions

View File

@ -613,8 +613,6 @@ if __name__ == '__main__':
#f.close()
updateWeather()
sys.exit()
try:
f = open('csv/last_updates.json', 'r')
last_updates = json.load(f)

View File

@ -1 +1 @@
{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["image.gif"]}
{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["open.gif"]}

View File

@ -1 +1 @@
{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["ZM.png", "WORK.png"]}
{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["XOM.png", "ZBRA.png"]}

Binary file not shown.

View File

@ -1,4 +1,4 @@
[Errno 2] No such file or directory: '/home/pi/Desktop/stock_ticker/ZM.png'. file: stockTicker.py. line: 2230. type: <class 'FileNotFoundError'>
[Errno 2] No such file or directory: '/home/pi/Desktop/stock_ticker/XOM.png'. file: stockTicker.py. line: 2230. type: <class 'FileNotFoundError'>
Traceback (most recent call last):
File "stockTicker.py", line 2230, in <module>
stock_ticker.process_msg(msg)
@ -14,4 +14,4 @@
image = Image.open(image_file)
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2634, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/Desktop/stock_ticker/ZM.png'
FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/Desktop/stock_ticker/XOM.png'

View File

@ -367,6 +367,28 @@ def feature_settings():
return index()
# saves files uploaded to the webpage for images and GIFs
@app.route("/upload", methods = ['PUT', 'POST', 'GET'])
def upload():
try:
images = request.files
names = list(request.files.keys())
for name in names:
images[name].save('user_uploads/' +name)
except Exception as e:
print(e)
return index()
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

View File

@ -486,11 +486,22 @@ var allFeaturesFileAddBtn = [
null,
];
var uploaded_images = [];
var uploaded_GIFs = [];
allFeaturesFileAddBtn.map((value, index) => {
if (value !== null) {
value.addEventListener("click", () => {
var tag = document.createElement("li");
tag.innerHTML = allFeaturesFile[index].files[0].name;
if (index == 10) {
uploaded_images.push(allFeaturesFile[index].files[0]);
} else if (index == 11) {
uploaded_GIFs.push(allFeaturesFile[index].files[0]);
}
allFeatures[index].appendChild(tag);
changeVarValue();
@ -685,6 +696,35 @@ function saveSettings() {
method:"PUT",
body:JSON.stringify(settings)
});
//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
});
}
}
let saveSettingsButtons = document.querySelectorAll(".save-btn-div").forEach(button =>

BIN
user_uploads/XOM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
user_uploads/ZBRA.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
user_uploads/open.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B