mirror of
https://gitlab.com/2-chainz/2-chainz-rest.git
synced 2025-08-03 03:51:24 +00:00
45 lines
1002 B
Python
45 lines
1002 B
Python
from fastapi import FastAPI
|
|
import json
|
|
import random
|
|
from starlette.responses import HTMLResponse
|
|
|
|
quotes = json.load(open("quotes.json"))
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/api")
|
|
async def quote():
|
|
return {"message": random.choice(quotes)}
|
|
|
|
|
|
@app.get("/api/dump")
|
|
async def dump():
|
|
return quotes
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
async def index():
|
|
quote = random.choice(quotes)
|
|
return f"""
|
|
<html>
|
|
<head>
|
|
<title>{quote}</title>
|
|
</head>
|
|
<body background='https://images.unsplash.com/photo-1540206395-68808572332f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1762&q=80'>
|
|
<h1 style='font-family: Impact, Charcoal, sans-serif;
|
|
font-size: 75px;
|
|
letter-spacing: 2px;
|
|
word-spacing: 2px;
|
|
color: #FFFFFF;
|
|
position: absolute;
|
|
top: 30%;
|
|
font-weight: 400;
|
|
text-decoration: none;
|
|
font-style: normal;
|
|
font-variant: normal;
|
|
text-transform: uppercase;'>{quote.replace('/','<br/>')}</h1>
|
|
</body>
|
|
</html>
|
|
"""
|