-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
40 lines (26 loc) · 834 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
from fastapi import FastAPI
import uvicorn
from lib.logic import search_wiki, wiki_phrase
from lib.logic import wiki as wiki_fetch
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 {"results": result}
@app.get("/wiki/{name}")
async def wiki(name: str):
"""Retrive wikipedia page"""
print("Get page for :", name)
result = wiki_fetch(name)
return {"results": result}
@app.get("/phrase/{name}")
async def phrase(name: str):
"""Retrive phrases from wikipedia page"""
result = wiki_phrase(name)
return {"results": result}
if __name__ == "__main__":
uvicorn.run(app, port=8080, host="0.0.0.0")