-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (54 loc) · 1.71 KB
/
Copy pathapp.py
File metadata and controls
67 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from __future__ import annotations
import logging
import os
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
from lib.ui import landing_page
from pydantic import BaseModel
import agent
from lib.config import competitor_list
app = FastAPI(title="Competitor Launch Watcher")
_log = logging.getLogger(__name__)
class RunResponse(BaseModel):
fetched: int
new: int
kept: int
digest: str
mail_sent: bool
dry_run: bool
@app.get("/health")
def health() -> dict[str, str]:
return {
"ok": "true",
"slug": "recipe-02-competitor-launch-watcher",
"llm_provider": os.environ.get("LLM_PROVIDER", "openai"),
"competitors": str(len(competitor_list())),
}
@app.post("/run", response_model=RunResponse)
def run(dry_run: bool = False) -> RunResponse:
try:
result = agent.run_watch(dry_run=dry_run)
except Exception:
_log.exception("request failed")
raise HTTPException(status_code=502, detail="upstream error")
return RunResponse(
fetched=result.fetched,
new=result.new,
kept=result.kept,
digest=result.digest,
mail_sent=result.mail_sent,
dry_run=result.dry_run,
)
@app.get("/", response_class=HTMLResponse)
def index() -> HTMLResponse:
return HTMLResponse(
landing_page(
title="Competitor Launch Watcher",
slug="recipe-02-competitor-launch-watcher",
tagline="Diff competitor launch pages and summarize what changed.",
endpoints=[
("POST", "/run?dry_run=1", "Fetch competitor pages and diff titles.")
],
pills=["vault-backed", "egress allowlist"],
)
)