-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
43 lines (28 loc) · 924 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
42
43
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 or /phrase"}
@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"""
# print(f"Passed in name: {name}")
result = wikiphrases(name)
# print(f"Result: {result}")
return {"result": result}
if __name__ == "__main__":
uvicorn.run(app, port=8080, host="0.0.0.0")