diff --git a/server.py b/server.py index 2a4b808..89ee98b 100755 --- a/server.py +++ b/server.py @@ -5,6 +5,7 @@ # stockTicker can not be copied and/or distributed without the express # permission of Neythen Treloar +from PIL import Image from flask import Flask, render_template, request from stockTicker import StockTicker from werkzeug.utils import secure_filename @@ -1755,6 +1756,67 @@ def scanNetworks2(): return (networks) +@app.route('/upload_stocks', methods=['POST']) +def upload_file_stocks(): + file = request.files['file'] + filename = file.filename + name, extension = os.path.splitext(filename) + capitalized_name = name.upper() + file_path = 'logos/stocks/' + capitalized_name + extension + file.save(file_path) + + image = Image.open(file_path) + + if image.height > 32: + new_width = int((32 / image.height) * image.width) + resized_image = image.resize((new_width, 32)) + resized_image.save(file_path) + resized_image.close() + image.close() + + image = Image.open(file_path) + + if image.mode in ('RGBA', 'LA') or (image.mode == 'P' and 'transparency' in image.info): + new_image = Image.new("RGBA", image.size, (0, 0, 0)) + new_image.paste(image, (0, 0), image) + new_image.save(file_path) + new_image.close() + image.close() + + return index() + + +@app.route('/upload_crypto', methods=['POST']) +def upload_file_crypto(): + file = request.files['file'] + filename = file.filename + name, extension = os.path.splitext(filename) + capitalized_name = name.upper() + file_path = 'logos/crypto/' + capitalized_name + extension + file.save(file_path) + + image = Image.open(file_path) + + if image.height > 32: + new_width = int((32 / image.height) * image.width) + resized_image = image.resize((new_width, 32)) + resized_image.save(file_path) + resized_image.close() + image.close() + + image = Image.open(file_path) + + if image.mode in ('RGBA', 'LA') or (image.mode == 'P' and 'transparency' in image.info): + new_image = Image.new("RGBA", image.size, (0, 0, 0)) + new_image.paste(image, (0, 0), image) + new_image.save(file_path) + new_image.close() + image.close() + + return index() + + + if __name__ == "__main__": app.run(host='0.0.0.0', port=1024, debug=False) # the debuggger causes flickering