adding and deleting crypto portfolio
This commit is contained in:
parent
985fb8392d
commit
2edb5540fd
62
server.py
62
server.py
@ -731,6 +731,42 @@ def savePortfolioSettings():
|
||||
|
||||
return index()
|
||||
|
||||
@app.route("/savePortfolioCryptoSettings", methods = ['PUT', 'POST'])
|
||||
def savePortfolioCryptoSettings():
|
||||
|
||||
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_crypto_settings.json' not in os.listdir('csv/'):
|
||||
with open('csv/portfolio_crypto_settings.json', 'w') as f:
|
||||
f.write(initialize_json)
|
||||
|
||||
try:
|
||||
f = open('csv/portfolio_crypto_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_crypto_settings.json", 'w+')
|
||||
json.dump(portfolio, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
return index()
|
||||
|
||||
|
||||
@app.route("/deletePortfolioSettings", methods = ['PUT', 'POST'])
|
||||
def deletePortfolioSettings():
|
||||
@ -758,6 +794,32 @@ def deletePortfolioSettings():
|
||||
|
||||
return index()
|
||||
|
||||
@app.route("/deletePortfolioCryptoSettings", methods = ['PUT', 'POST'])
|
||||
def deletePortfolioCryptoSettings():
|
||||
|
||||
data= request.data.decode('utf-8')
|
||||
settings = json.loads(data)
|
||||
|
||||
try:
|
||||
g = open('csv/portfolio_crypto_settings.json')
|
||||
portfolio = json.load(g)
|
||||
g.close()
|
||||
|
||||
symbol = settings
|
||||
# DELETE SYMBOLS FUNCTION
|
||||
try:
|
||||
portfolio['symbols'].pop(symbol)
|
||||
except:
|
||||
pass
|
||||
|
||||
f = open("csv/portfolio_crypto_settings.json", 'w+')
|
||||
json.dump(portfolio, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
return index()
|
||||
|
||||
|
||||
@app.route("/screensaver", methods = ['PUT', 'POST'])
|
||||
def screensaver():
|
||||
|
Loading…
Reference in New Issue
Block a user