steveagi commited on
Commit
79c61ed
·
1 Parent(s): 80a4555
Files changed (2) hide show
  1. game_util.py +7 -0
  2. main.py +30 -10
game_util.py CHANGED
@@ -4,6 +4,9 @@ import requests
4
 
5
  from fastapi import HTTPException, status
6
 
 
 
 
7
 
8
  def read(game: str, code: str, command: str):
9
  _code = os.getenv("hfs_code")
@@ -23,5 +26,9 @@ def read(game: str, code: str, command: str):
23
  return json.loads(x.text)
24
 
25
 
 
 
 
 
26
  def delete(game: str, code: str, command: str):
27
  raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED)
 
4
 
5
  from fastapi import HTTPException, status
6
 
7
+ def create(game: str, code: str, command: str):
8
+ raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED)
9
+
10
 
11
  def read(game: str, code: str, command: str):
12
  _code = os.getenv("hfs_code")
 
26
  return json.loads(x.text)
27
 
28
 
29
+ def update(game: str, code: str, command: str):
30
+ raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED)
31
+
32
+
33
  def delete(game: str, code: str, command: str):
34
  raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED)
main.py CHANGED
@@ -9,22 +9,42 @@ app = FastAPI()
9
  def root():
10
  return {"message": "hi!"}
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- @app.post("/games/snake/nlp/r")
 
14
  def main_snake(code: str=Body(), command: str=Body()):
15
- return game_util.read("snake", code, command)
16
 
17
 
18
- @app.post("/games/snake/nlp/d")
19
  def main_snake(code: str=Body(), command: str=Body()):
20
- return game_util.delete("angrybird", code, command)
21
 
22
 
23
- @app.post("/games/angrybird/nlp/r")
24
- def main_angrybird(code: str=Body(), command: str=Body()):
25
- return game_util.read("angrybird", code, command)
26
 
27
 
28
- @app.post("/games/angrybird/nlp/d")
29
- def main_angrybird(code: str=Body(), command: str=Body()):
30
- return game_util.delete("angrybird", code, command)
 
9
  def root():
10
  return {"message": "hi!"}
11
 
12
+ GAME = "sname"
13
+ @app.post(f"/games/{GAME}/nlp/c", tags=[GAME])
14
+ def main_snake(code: str=Body(), command: str=Body()):
15
+ return game_util.create(GAME, code, command)
16
+
17
+
18
+ @app.post(f"/games/{GAME}/nlp/r", tags=[GAME])
19
+ def main_snake(code: str=Body(), command: str=Body()):
20
+ return game_util.read(GAME, code, command)
21
+
22
+
23
+ @app.post(f"/games/{GAME}/nlp/u", tags=[GAME])
24
+ def main_snake(code: str=Body(), command: str=Body()):
25
+ return game_util.update(GAME, code, command)
26
+
27
+
28
+ @app.post(f"/games/{GAME}/nlp/d", tags=[GAME])
29
+ def main_snake(code: str=Body(), command: str=Body()):
30
+ return game_util.delete(GAME, code, command)
31
 
32
+ GAME = "angrybird"
33
+ @app.post(f"/games/{GAME}/nlp/c", tags=[GAME])
34
  def main_snake(code: str=Body(), command: str=Body()):
35
+ return game_util.create(GAME, code, command)
36
 
37
 
38
+ @app.post(f"/games/{GAME}/nlp/r", tags=[GAME])
39
  def main_snake(code: str=Body(), command: str=Body()):
40
+ return game_util.read(GAME, code, command)
41
 
42
 
43
+ @app.post(f"/games/{GAME}/nlp/u", tags=[GAME])
44
+ def main_snake(code: str=Body(), command: str=Body()):
45
+ return game_util.update(GAME, code, command)
46
 
47
 
48
+ @app.post(f"/games/{GAME}/nlp/d", tags=[GAME])
49
+ def main_snake(code: str=Body(), command: str=Body()):
50
+ return game_util.delete(GAME, code, command)