bug fix: last sync time is the lastest file modified in data_cache, change app.py and index.html
This commit is contained in:
@@ -74,12 +74,19 @@ def get_summary():
|
||||
instruments = engine.load_instruments_from_csv('instruments.csv')
|
||||
|
||||
results = []
|
||||
latest_mtime = 0 # To track the actual freshest data file
|
||||
|
||||
for item in instruments:
|
||||
# Update engine target
|
||||
engine.symbol = item['symbol'].strip().upper()
|
||||
engine.file_path = os.path.join(engine.cache_dir, f"{engine.symbol}.csv")
|
||||
|
||||
metrics = engine.get_local_metrics()
|
||||
# --- NEW: UPDATE LATEST_MTIME HERE ---
|
||||
if os.path.exists(engine.file_path):
|
||||
file_time = os.path.getmtime(engine.file_path)
|
||||
if file_time > latest_mtime:
|
||||
latest_mtime = file_time
|
||||
# -------------------------------------
|
||||
metrics = engine.get_local_metrics()
|
||||
display_name = item.get('name') or engine.symbol
|
||||
|
||||
if metrics:
|
||||
@@ -97,8 +104,17 @@ def get_summary():
|
||||
'last_close': 'N/A',
|
||||
'error': True
|
||||
})
|
||||
|
||||
return jsonify(results)
|
||||
# Format the latest sync time found
|
||||
if latest_mtime > 0:
|
||||
last_mod_time = datetime.fromtimestamp(latest_mtime).strftime('%d/%b %H:%M:%S')
|
||||
else:
|
||||
last_mod_time = "Never"
|
||||
|
||||
return jsonify({
|
||||
"last_sync": last_mod_time,
|
||||
"data": results # Fixed the 'data_list' syntax error here
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/sync', methods=['POST'])
|
||||
def run_sync():
|
||||
|
||||
Reference in New Issue
Block a user