Feat: [main] news-summary-bot 완성
All checks were successful
news-summary-bot-cicd / build_push_deploy (push) Successful in 11m43s
All checks were successful
news-summary-bot-cicd / build_push_deploy (push) Successful in 11m43s
This commit is contained in:
36
app/main.py
Normal file
36
app/main.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from fastapi import FastAPI, Header, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.config import settings
|
||||
from app.discord import send_to_discord
|
||||
from app.summarizer import summarize
|
||||
from app.transcript import extract_video_id, fetch_transcript
|
||||
|
||||
app = FastAPI(title="News Summary Bot")
|
||||
|
||||
|
||||
class SummarizeRequest(BaseModel):
|
||||
video_url: str
|
||||
title: str = ""
|
||||
|
||||
|
||||
@app.post("/api/news/summarize")
|
||||
async def summarize_video(
|
||||
req: SummarizeRequest,
|
||||
x_api_secret: str = Header(default=""),
|
||||
):
|
||||
if settings.api_secret and x_api_secret != settings.api_secret:
|
||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||
|
||||
video_id = extract_video_id(req.video_url)
|
||||
transcript = fetch_transcript(video_id)
|
||||
title = req.title or video_id
|
||||
summary = summarize(transcript, title)
|
||||
await send_to_discord(title, req.video_url, summary)
|
||||
|
||||
return {"status": "ok", "title": title, "summary_length": len(summary)}
|
||||
|
||||
|
||||
@app.get("/api/news/health")
|
||||
async def health():
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user