steveagi commited on
Commit
20ec496
·
1 Parent(s): 6c875ce
Files changed (2) hide show
  1. main.py +1 -1
  2. routers/game_util.py +9 -6
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, Body
2
  from routers import root, snake, watermelon
3
 
4
  app = FastAPI()
 
1
+ from fastapi import FastAPI
2
  from routers import root, snake, watermelon
3
 
4
  app = FastAPI()
routers/game_util.py CHANGED
@@ -16,17 +16,20 @@ def read(game: str, code: str, command: str):
16
  raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
17
 
18
  url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
19
- print(url)
20
  myobj = {
21
  'command': command,
22
  }
23
- headers = {'Authorization': f'Bearer {os.getenv("hfs_token")}'}
 
 
24
 
25
  x = requests.post(url, json=myobj, headers=headers)
26
- if x.status_code == status.HTTP_200_OK:
27
- return json.loads(x.text)
28
- else:
29
- raise HTTPException(status_code=x.status_code, detail=json.loads(x.text)['detail'])
 
 
30
 
31
 
32
  def update(game: str, code: str, command: str):
 
16
  raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
17
 
18
  url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
 
19
  myobj = {
20
  'command': command,
21
  }
22
+ headers = {
23
+ 'Authorization': f'Bearer {os.getenv("hfs_token")}',
24
+ }
25
 
26
  x = requests.post(url, json=myobj, headers=headers)
27
+ if x.status_code != status.HTTP_200_OK:
28
+ raise HTTPException(
29
+ status_code=x.status_code,
30
+ detail=json.loads(x.text)['detail'],
31
+ )
32
+ return json.loads(x.text)
33
 
34
 
35
  def update(game: str, code: str, command: str):