forked from noahgift/functions-from-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (27 loc) · 871 Bytes
/
Copy pathmain.py
File metadata and controls
36 lines (27 loc) · 871 Bytes
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
# pylint: disable=no-name-in-module
# pylint: disable=no-self-argument
import uvicorn
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from fastapi import FastAPI
from pydantic import BaseModel
from mylib.bot import scrape
app = FastAPI()
class Wiki(BaseModel):
name: str
@app.post("/wiki")
async def scrape_story(wiki: Wiki):
result = scrape(name=wiki.name)
payload = {"wikipage": result}
json_compatible_item_data = jsonable_encoder(payload)
return JSONResponse(content=json_compatible_item_data)
@app.get("/")
async def root():
return {"message": "Hello Functions"}
@app.get("/add/{num1}/{num2}")
async def add(num1: int, num2: int):
"""Add two numbers together"""
total = num1 + num2
return {"total": total}
if __name__ == '__main__':
uvicorn.run(app, port=8080, host='0.0.0.0')