File size: 438 Bytes
f3333e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastapi import FastAPI
from pydantic import BaseModel
from utils import fetch_news, analyze_sentiment

app = FastAPI()

class NewsRequest(BaseModel):
    company: str

@app.post("/get_news/")
def get_news(data: NewsRequest):
    news_articles = fetch_news(data.company)
    for article in news_articles:
        article["sentiment"] = analyze_sentiment(article["summary"])
    
    return {"articles": news_articles}