From f1c01d1877fe0addcd981c1597cbb1e504b1967d Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 26 Sep 2023 12:47:20 +0800 Subject: [PATCH] save global portfolio function --- server.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/server.py b/server.py index b782399..e478ac8 100755 --- a/server.py +++ b/server.py @@ -1202,6 +1202,37 @@ def savePortfolioSettings(): return index() +@app.route("/saveGlobalPortfolioSettings", methods = ['PUT', 'POST']) +def saveGlobalPortfolioSettings(): + + 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_global_settings.json' not in os.listdir('csv/'): + with open('csv/portfolio_global_settings.json', 'w') as f: + f.write(initialize_json) + try: + f = open('csv/portfolio_global_settings.json') + portfolio = json.load(f) + f.close() + + shares1 = settings['shares'] + cost1 = settings['cost'] + symbol1 = settings['symbol'] + days1 = settings['days'] + # day_start = datetime.datetime.strptime(str(days1), "%Y-%m-%d") + # day_today = datetime.datetime.strptime(datetime.datetime.now(pytz.utc).strftime("%Y-%m-%d"), "%Y-%m-%d") + # days1 = str((day_today - day_start).days) + portfolio['symbols'][symbol1] = {'shares':shares1, 'day':days1, 'cost':cost1} + + f = open("csv/portfolio_global_settings.json", 'w+') + json.dump(portfolio, f) + f.close() + except: + pass + @app.route("/savePortfolioCryptoSettings", methods = ['PUT', 'POST']) def savePortfolioCryptoSettings():