Shubham0786 commited on
Commit
d28f23b
·
verified ·
1 Parent(s): c01493b

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +25 -0
api.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from utils import fetch_news, analyze_sentiment, summarize_text
3
+
4
+ app = FastAPI()
5
+
6
+ @app.get("/news/{company_name}")
7
+ def get_news(company_name: str):
8
+ articles = fetch_news(company_name)
9
+ return {"company": company_name, "articles": articles}
10
+
11
+ @app.get("/analyze/{company_name}")
12
+ def analyze_company(company_name: str):
13
+ articles = fetch_news(company_name)
14
+ report = {"Company": company_name, "Articles": []}
15
+
16
+ for article in articles[:10]:
17
+ summary = summarize_text(article['content'])
18
+ sentiment = analyze_sentiment(article['content'])
19
+ report["Articles"].append({
20
+ "Title": article['title'],
21
+ "Summary": summary,
22
+ "Sentiment": sentiment,
23
+ "Topics": ["Business"]
24
+ })
25
+ return report