-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (32 loc) · 954 Bytes
/
main.py
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
from fastapi import FastAPI, status
from fastapi.responses import JSONResponse
from utils import getQuote
app = FastAPI()
@app.get("/")
def random():
quote, author, link = getQuote()
if quote == None:
data = {
"error": "An error occurred."
}
return JSONResponse(content=data, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
data = {
"quote": quote,
"author": author,
"link": link
}
return JSONResponse(content=data, status_code=status.HTTP_200_OK)
@app.get("/{url}")
def custom(url):
quote, author, link = getQuote(url)
if quote == None:
data = {
"error": "An error occurred."
}
return JSONResponse(content=data, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
data = {
"quote": quote,
"author": author,
"link": link
}
return JSONResponse(content=data, status_code=status.HTTP_200_OK)