-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
91 lines (72 loc) · 2.44 KB
/
api.py
File metadata and controls
91 lines (72 loc) · 2.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from nltk import edit_distance
app = FastAPI()
if __name__ == "__main__" :
uvicorn.run("api:app", host="127.0.0.1", port=8000, log_level="info")
# ----------------------------
import main
import gamedata
import userdata
import schema
# ----------------------------
# http://127.0.0.1:8000/docs
# uvicorn api:app --reload
# python -m uvicorn api:app --reload
#----------------DON'T TOUCH------------------------#
origins = [
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins = origins,
allow_credentials = True,
allow_methods = ["*"],
allow_headers = ["*"],
)
#----------------DON'T TOUCH------------------------#
# @app.get("/") # Recommend from search History
# async def index():
# result = main.searchuserhistory()
# return result
@app.get('/currentuser') # get current user
async def currentuser():
return main.currentuser
@app.post('/login') # log in
async def login(login: schema.Login):
login = main.login(login.username, login.password)
return login
@app.post('/signup') # sign up
async def signup(signup: schema.Signup):
signup = main.signup(signup.username, signup.password)
return signup
@app.get('/logout') # log out
async def logout():
logout = main.logout()
return logout
@app.get('/gettags') # get common tags
async def gettags():
return gamedata.genre
@app.get('/getsteam') # get image source
async def getsteam(gamename: str):
return main.getsteam(gamename)
@app.get('/searchbyname') # find best match from name
async def searchname(name: str):
return main.searchbyname(name)
@app.get('/seachbestmatch') # find best match for query
async def seachbestmatch(tags: str, playertype: str):
return main.websearch(tags, playertype)
# Test : 110101010000011001000001001011 | Must show Black Myth: Wukong
@app.get('/searchtag') # find best match for single tag
async def searchtag(tag: str, playertype: str):
return main.websearchtag(tag, playertype)
@app.get('/besthistorymatch') # find best match from search history
async def besthistorymatch():
return main.searchuserhistory()
@app.get('/get_game_name_list') # get game name list
async def get_game_name_list():
return [game.name for game in gamedata.gamelst[:3000]]
@app.get('/mca_best_match') # find best match from mca
async def mca_best_match(game_name: str):
return main.mca_best_match(game_name)