-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi.py
More file actions
54 lines (42 loc) · 1.29 KB
/
Copy pathapi.py
File metadata and controls
54 lines (42 loc) · 1.29 KB
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
44
45
46
47
48
49
50
51
52
53
54
"""Module for API calls."""
from fastapi import FastAPI, Query
from akshara import varnakaarya as vk
app = FastAPI()
@app.get("/vinyaasa")
async def api_vinyaasa(
word: str = Query(..., description="The word to compute the vinyaasa for")
):
"""Return the vinyaasa of a word."""
try:
vinyaasa = vk.get_vinyaasa(word)
status = "success"
except AssertionError:
vinyaasa = None
status = "failure"
return {"vinyaasa": vinyaasa, "status": status}
@app.get("/akshara")
async def api_akshara(
word: str = Query(..., description="The word to compute the akshara for")
):
"""Return the akshara of a word."""
try:
akshara = vk.get_akshara(word)
status = "success"
except AssertionError:
return {"akshara": None, "status": "failure"}
return {"akshara": akshara, "status": status}
@app.get("/shabda")
async def api_shabda(
letters: str = Query(
..., description="Comma-separated letters to compute the shabda for"
)
):
"""Return the shabda of a list of letters."""
try:
letter_list = letters.split(",")
shabda = vk.get_shabda(letter_list)
status = "success"
except AssertionError:
shabda = None
status = "failure"
return {"word": shabda, "status": status}