40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from fastapi import FastAPI, Request
|
|
from fastapi.responses import HTMLResponse, JSONResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
from fastapi.staticfiles import StaticFiles
|
|
from pathlib import Path
|
|
import download
|
|
import json
|
|
|
|
app = FastAPI()
|
|
|
|
# Mount static files if needed (e.g. CSS, JS, images)
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
# Jinja2 template directory
|
|
templates = Jinja2Templates(directory="templates")
|
|
|
|
|
|
# api
|
|
@app.get("/dropoutUpdate")
|
|
async def grab():
|
|
return download.dropout.series()
|
|
|
|
@app.get("/dropoutSeries", response_class=JSONResponse)
|
|
async def read():
|
|
file_path = Path("data/dropout.json")
|
|
if file_path.exists():
|
|
with file_path.open("r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
return JSONResponse(content=data)
|
|
return JSONResponse(content={"error": "File not found"}, status_code=404)
|
|
|
|
@app.get("/dropoutDownload")
|
|
async def download(show: str, season: str, episode: str):
|
|
download.dropout.show(show,season,episode)
|
|
|
|
# html
|
|
@app.get("/", response_class=HTMLResponse)
|
|
async def read_root(request: Request):
|
|
return templates.TemplateResponse("index.html", {"request": request, "message": "Hello from FastAPI + Jinja2!"})
|