-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (26 loc) · 841 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
36
37
38
39
40
41
from fastapi import FastAPI
import uvicorn
from mylib.logic import search_wiki
from mylib.logic import wiki as wikilogic
from mylib.logic import phrase as wikiphrases
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Wikipedia API. Call/Search or /wiki"}
@app.get("/search/{value}")
async def search(value: str):
"""Page to search in wikipedia"""
result = search_wiki(value)
return {"result": result}
@app.get("/wiki/{name}")
async def wiki(name: str):
"""Retrieve Wikipedia page"""
result = wikilogic(name)
return {"result": result}
@app.get("/phrase/{name}")
async def phrase(name: str):
"""Retrieve Wikipedia page and return phrases"""
result = wikiphrases(name)
return {"result": result}
if __name__ == "__main__":
uvicorn.run(app, port=8000, host="0.0.0.0")