blunderboard/request_test.py

44 lines
1.1 KiB
Python
Raw Normal View History

2022-12-29 23:26:59 +00:00
import requests
# Replace YOUR_API_TOKEN with the API token you are using for authentication
API_TOKEN = "blunderboard-security-token"
# Set the API endpoint URL
url = "http://5.75.138.151:5000/api/get_evaluation"
2022-12-30 12:27:37 +00:00
wdl_api = "http://5.75.138.151:5000/api/get_wdl"
2022-12-29 23:26:59 +00:00
# Set the chess position and search depth
2022-12-30 12:27:37 +00:00
data = {
"position": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"depth": 20,
}
2022-12-29 23:26:59 +00:00
# Set the API token in the request header
2022-12-30 12:27:37 +00:00
headers = {"Authorization": API_TOKEN}
2022-12-29 23:26:59 +00:00
# Send a POST request to the API endpoint
response = requests.post(url, json=data, headers=headers)
# Print the response content from the server
if response.status_code == 200:
print(response.json())
else:
2022-12-30 12:27:37 +00:00
print("Error: " + response.json()["error"])
def api_wdl() -> str:
"""
Returns the current wdl from the REST API
:return: str
"""
# Send a POST request to the API endpoint
response2 = requests.post(wdl_api, json=data, headers=headers)
if response2.status_code == 200:
return response2.json()
else:
print("API Error: " + response2.json()["error"])
return "API Error"
print(api_wdl())