-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrun_example.sh
executable file
·67 lines (55 loc) · 1.86 KB
/
run_example.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
source ../.env
function generate_request_body() {
cat << EOF
{
"source_code": "",
"language_id": 89,
"additional_files": "$(cd additional_files; zip -r - . | $JUDGE0_BASE64_CMD -w0 -)"
}
EOF
}
function create_submission() {
echo "[$(date)] Generating request body..." 1>&2
generate_request_body > request_body.json
echo "[$(date)] Creating submission..." 1>&2
# Use these headers for RapidAPI
# -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
# -H "X-RapidAPI-Host: judge0-ce.p.rapidapi.com" \
curl --progress-bar \
--no-silent \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SULU_KEY" \
--data @request_body.json \
--output request_response.json \
"$JUDGE0_CE_BASE_URL/submissions?base64_encoded=true&wait=false"
cat request_response.json
}
function get_submission() {
# Use these headers for RapidAPI
# -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
# -H "X-RapidAPI-Host: judge0-ce.p.rapidapi.com" \
curl -H "Accept: application/json" \
-H "Authorization: Bearer $SULU_KEY" \
"$JUDGE0_CE_BASE_URL/submissions/$1?base64_encoded=true&fields=$2"
}
token="$(create_submission | jq -r ".token")"
if [[ "$token" == "null" ]]; then
cat request_response.json | jq
exit
fi
echo "[$(date)] Token: $token"
for i in {1..10}; do
sleep $(( i / 2 ))
status_id="$(get_submission "$token" "status" | jq -r ".status.id")"
echo "[$(date)] Status ID: $status_id"
if [[ "$status_id" != "1" && "$status_id" != "2" ]]; then
break
fi
done
submission_json="$(get_submission "$token" "status,stdout,stderr,compile_output,message")"
echo "[$(date)] Received submission:"
echo "$submission_json" | jq
echo "[$(date)] Base64 decoded stdout:"
echo "$submission_json" | jq -r ".stdout" | $JUDGE0_BASE64_CMD -d -