polish
Browse files- main.py +1 -1
- routers/game_util.py +9 -6
main.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 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 = {
|
|
|
|
|
|
|
| 24 |
|
| 25 |
x = requests.post(url, json=myobj, headers=headers)
|
| 26 |
-
if x.status_code =
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 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):
|