steveagi commited on
Commit
3f3154b
·
1 Parent(s): 3127048

rename to code

Browse files
Files changed (2) hide show
  1. game_util.py +5 -5
  2. main.py +8 -8
game_util.py CHANGED
@@ -5,11 +5,11 @@ import requests
5
  from fastapi import HTTPException, status
6
 
7
 
8
- def read(game: str, passcode: str, command: str):
9
- code = os.getenv("hfs_code")
10
- if code is None:
11
  raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
12
- if passcode != code:
13
  raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
14
 
15
  url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
@@ -23,5 +23,5 @@ def read(game: str, passcode: str, command: str):
23
  return json.loads(x.text)
24
 
25
 
26
- def delete(game: str, passcode: str, command: str):
27
  raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED)
 
5
  from fastapi import HTTPException, status
6
 
7
 
8
+ def read(game: str, code: str, command: str):
9
+ _code = os.getenv("hfs_code")
10
+ if +code is None:
11
  raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
12
+ if code != _code:
13
  raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
14
 
15
  url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
 
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)
main.py CHANGED
@@ -11,20 +11,20 @@ def root():
11
 
12
 
13
  @app.post("/games/snake/nlp/r")
14
- def main_snake(passcode: str=Body(), command: str=Body()):
15
- return game_util.read("snake", passcode, command)
16
 
17
 
18
  @app.post("/games/snake/nlp/d")
19
- def main_snake(passcode: str=Body(), command: str=Body()):
20
- return game_util.delete("angrybird", passcode, command)
21
 
22
 
23
  @app.post("/games/angrybird/nlp/r")
24
- def main_angrybird(passcode: str=Body(), command: str=Body()):
25
- return game_util.read("angrybird", passcode, command)
26
 
27
 
28
  @app.post("/games/angrybird/nlp/d")
29
- def main_angrybird(passcode: str=Body(), command: str=Body()):
30
- return game_util.delete("angrybird", passcode, command)
 
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)