File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change 1
- """
2
- uvicorn main:app --reload
3
- """
4
-
5
1
import pathlib
6
2
from unicodedata import name
7
3
11
7
12
8
from charindex import InvertedIndex
13
9
14
- app = FastAPI (
10
+ app = FastAPI ( # <1>
15
11
title = 'Mojifinder Web' ,
16
12
description = 'Search for Unicode characters by name.' ,
17
13
)
18
14
19
- class CharName (BaseModel ):
15
+ class CharName (BaseModel ): # <2>
20
16
char : str
21
17
name : str
22
18
23
- def init (app ):
19
+ def init (app ): # <3>
24
20
app .state .index = InvertedIndex ()
25
21
static = pathlib .Path (__file__ ).parent .absolute () / 'static'
26
22
with open (static / 'form.html' ) as fp :
27
23
app .state .form = fp .read ()
28
24
29
- init (app )
25
+ init (app ) # <4>
26
+
27
+ @app .get ('/search' , response_model = list [CharName ]) # <5>
28
+ async def search (q : str ): # <6>
29
+ chars = app .state .index .search (q )
30
+ return ({'char' : c , 'name' : name (c )} for c in chars ) # <7>
30
31
31
- @app .get ('/' , response_class = HTMLResponse , include_in_schema = False )
32
+ @app .get ('/' , # <8>
33
+ response_class = HTMLResponse ,
34
+ include_in_schema = False )
32
35
def form ():
33
36
return app .state .form
34
-
35
- @app .get ('/search' , response_model = list [CharName ])
36
- async def search (q : str ):
37
- chars = app .state .index .search (q )
38
- return [{'char' : c , 'name' : name (c )} for c in chars ]
You can’t perform that action at this time.
0 commit comments