From 6cd628b0cf1b69ce45aba962fde956e4427a5052 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 16 Mar 2023 19:08:13 +0800 Subject: [PATCH] fixed indentation issues with saveportfoliosettings --- server.py | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/server.py b/server.py index 7048bed..0ee6d78 100755 --- a/server.py +++ b/server.py @@ -697,39 +697,40 @@ def saveIpoAPIKey(): @app.route("/savePortfolioSettings", methods = ['PUT', 'POST']) def savePortfolioSettings(): - + data= request.data.decode('utf-8') settings = json.loads(data) - - #THIS IS TO CREATE PORTFOLIO JSON FILE IF IT DOESN'T EXIST - initialize_json = '{"symbols":{}}' - if 'portfolio_settings.json' not in os.listdir('csv/'): - with open('csv/portfolio_settings.json', 'w') as f: - f.write(initialize_json) + + #THIS IS TO CREATE PORTFOLIO JSON FILE IF IT DOESN'T EXIST + initialize_json = '{"symbols":{}}' + if 'portfolio_settings.json' not in os.listdir('csv/'): + with open('csv/portfolio_settings.json', 'w') as f: + f.write(initialize_json) + + try: + f = open('csv/portfolio_settings.json') + portfolio = json.load(f) + f.close() - try: - f = open('csv/portfolio_settings.json') - portfolio = json.load(f) - f.close() + shares1 = settings['shares'] + cost1 = settings['cost'] + symbol1 = settings['symbol'] + + days1 = settings['days'] + day_start = datetime.strptime(days1, "%Y-%m-%d") + day_today = datetime.strptime(datetime.now(pytz.utc).strftime("%Y-%m-%d"), "%Y-%m-%d") + days1 = str((day_today - day_start).days) - shares1 = settings['shares'] - cost1 = settings['cost'] - symbol1 = settings['symbol'] + portfolio['symbols'][symbol1] = {'shares':shares1, 'day':days1, 'cost':cost1} - days1 = settings['days'] - day_start = datetime.strptime(days1, "%Y-%m-%d") - day_today = datetime.strptime(datetime.now(pytz.utc).strftime("%Y-%m-%d"), "%Y-%m-%d") - days1 = str((day_today - day_start).days) + f = open("csv/portfolio_settings.json", 'w+') + json.dump(portfolio, f) + f.close() + except: + pass - portfolio['symbols'][symbol1] = {'shares':shares1, 'day':days1, 'cost':cost1} + return index() - f = open("csv/portfolio_settings.json", 'w+') - json.dump(portfolio, f) - f.close() - except: - pass - - return index() @app.route("/screensaver", methods = ['PUT', 'POST']) def screensaver():