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-
51import pathlib
62from unicodedata import name
73
117
128from charindex import InvertedIndex
139
14- app = FastAPI (
10+ app = FastAPI ( # <1>
1511 title = 'Mojifinder Web' ,
1612 description = 'Search for Unicode characters by name.' ,
1713)
1814
19- class CharName (BaseModel ):
15+ class CharName (BaseModel ): # <2>
2016 char : str
2117 name : str
2218
23- def init (app ):
19+ def init (app ): # <3>
2420 app .state .index = InvertedIndex ()
2521 static = pathlib .Path (__file__ ).parent .absolute () / 'static'
2622 with open (static / 'form.html' ) as fp :
2723 app .state .form = fp .read ()
2824
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>
3031
31- @app .get ('/' , response_class = HTMLResponse , include_in_schema = False )
32+ @app .get ('/' , # <8>
33+ response_class = HTMLResponse ,
34+ include_in_schema = False )
3235def form ():
3336 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