diff --git a/app.py b/app.py index 3a260aa..36e40bb 100644 --- a/app.py +++ b/app.py @@ -5,9 +5,53 @@ import concurrent.futures from flask_caching import Cache import csv, os, logging from concurrent.futures import ThreadPoolExecutor +import pandas as pd + app = Flask(__name__) cache = Cache(app, config={'CACHE_TYPE': 'SimpleCache'}) +# The CSV is in the root directory (same level as app.py) +CSV_PATH = os.path.join(os.path.dirname(__file__), 'instruments.csv') + +@app.route('/settings') +def settings(): + instruments = [] + last_updated = "Never" + + if os.path.exists(CSV_PATH): + # 1. Get the last modified time from the Synology filesystem + mtime = os.path.getmtime(CSV_PATH) + last_updated = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S') + + # 2. Read the data + df = pd.read_csv(CSV_PATH) + df = df.fillna('') + instruments = df.to_dict(orient='records') + + return render_template('settings.html', instruments=instruments, last_updated=last_updated) + +@app.route('/settings/save', methods=['POST']) +def save_settings(): + try: + names = request.form.getlist('name[]') + cusips = request.form.getlist('cusip[]') + providers = request.form.getlist('provider[]') + + # Create a new DataFrame from the web form data + new_data = { + 'name': [s.strip() for s in names if s.strip()], + 'cusip': [u.strip() for u in cusips if u.strip()], + 'provider': [p.strip() for p in providers if p.strip()] + } + + df = pd.DataFrame(new_data) + # Save directly back to the root folder + df.to_csv(CSV_PATH, index=False) + + return redirect('/settings') + except Exception as e: + print(f"Error saving CSV: {e}") + return "Internal Server Error", 500 @cache.memoize(timeout=3600) def fetch_and_calculate(config): diff --git a/instruments.csv b/instruments.csv index 9994c62..71989b4 100644 --- a/instruments.csv +++ b/instruments.csv @@ -1,4 +1,4 @@ -symbol,cusip,provider +name,cusip,provider JPMorgan Evergreen,HK0000055829,jpm Allianz Oriental Income Cl A,LU0348783233:USD,agi SPMO ETF - USD,SPMO,yahoo