Signe22 commited on
Commit
50f0f1f
·
verified ·
1 Parent(s): b04e9aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from pathlib import Path
2
  import sqlite3
3
  from typing import Optional
@@ -9,6 +10,9 @@ from fastapi.middleware.cors import CORSMiddleware
9
 
10
  app = FastAPI(title="Green Energy News API", version="1.0.0")
11
 
 
 
 
12
  DB_PATH = Path("/app/data/news.db")
13
 
14
  app.add_middleware(
@@ -71,7 +75,7 @@ def get_daily_summary():
71
  summary_date,
72
  short_summary,
73
  key_focus,
74
- top_stories,
75
  generated_at
76
  FROM daily_summaries
77
  ORDER BY summary_date DESC
@@ -86,13 +90,40 @@ def get_daily_summary():
86
 
87
  row = df.iloc[0].to_dict()
88
 
89
- if row.get("top_stories"):
 
 
 
 
 
 
 
90
  try:
91
- row["top_stories"] = json.loads(row["top_stories"])
 
 
 
 
92
  except Exception:
93
  pass
94
 
95
- return row
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  @app.get("/summary/daily-actions")
98
  def daily_actions(
 
1
+ # api/app.py
2
  from pathlib import Path
3
  import sqlite3
4
  from typing import Optional
 
10
 
11
  app = FastAPI(title="Green Energy News API", version="1.0.0")
12
 
13
+ import os
14
+ from pathlib import Path
15
+
16
  DB_PATH = Path("/app/data/news.db")
17
 
18
  app.add_middleware(
 
75
  summary_date,
76
  short_summary,
77
  key_focus,
78
+ summary_json,
79
  generated_at
80
  FROM daily_summaries
81
  ORDER BY summary_date DESC
 
90
 
91
  row = df.iloc[0].to_dict()
92
 
93
+ result = {
94
+ "summary_date": row.get("summary_date"),
95
+ "generated_at": row.get("generated_at"),
96
+ }
97
+
98
+ summary_json = row.get("summary_json")
99
+
100
+ if summary_json:
101
  try:
102
+ parsed_summary = json.loads(summary_json)
103
+
104
+ if isinstance(parsed_summary, dict):
105
+ result.update(parsed_summary)
106
+
107
  except Exception:
108
  pass
109
 
110
+ # fallback compatibility
111
+ if "executive_summary" not in result:
112
+ result["executive_summary"] = row.get("short_summary")
113
+
114
+ if "recommended_focus" not in result:
115
+ result["recommended_focus"] = row.get("key_focus")
116
+
117
+ if "decision_implications" not in result:
118
+ result["decision_implications"] = []
119
+
120
+ if "watchlist" not in result:
121
+ result["watchlist"] = []
122
+
123
+ if "top_stories" not in result:
124
+ result["top_stories"] = []
125
+
126
+ return result
127
 
128
  @app.get("/summary/daily-actions")
129
  def daily_actions(