fromozu commited on
Commit
04dc7eb
·
verified ·
1 Parent(s): ea95a11

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -479,6 +479,35 @@ async def get_sector_rotation_report(trade_date: str):
479
  conn.close()
480
 
481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  # Hugging Face Spaces 使用 7860 端口
483
  if __name__ == "__main__":
484
  import uvicorn
 
479
  conn.close()
480
 
481
 
482
+ @app.get("/api/sector-rotation-reports/{trade_date}/html")
483
+ async def get_sector_rotation_report_html(trade_date: str):
484
+ """获取指定交易日的板块轮动报告(直接返回HTML页面)"""
485
+ conn = get_connection()
486
+ try:
487
+ with conn.cursor() as cursor:
488
+ cursor.execute("""
489
+ SELECT html_content
490
+ FROM sector_rotation_reports
491
+ WHERE trade_date = %s
492
+ """, (trade_date,))
493
+ report = cursor.fetchone()
494
+
495
+ if not report or not report['html_content']:
496
+ return HTMLResponse(
497
+ content=f"<html><body><h1>未找到 {trade_date} 的板块轮动报告</h1></body></html>",
498
+ status_code=404
499
+ )
500
+
501
+ return HTMLResponse(content=report['html_content'])
502
+ except Exception as e:
503
+ return HTMLResponse(
504
+ content=f"<html><body><h1>加载失败</h1><p>{str(e)}</p></body></html>",
505
+ status_code=500
506
+ )
507
+ finally:
508
+ conn.close()
509
+
510
+
511
  # Hugging Face Spaces 使用 7860 端口
512
  if __name__ == "__main__":
513
  import uvicorn