Created
July 7, 2022 04:08
-
-
Save badri/e28196652069e8a02e53c7abad1b97da to your computer and use it in GitHub Desktop.
Judge0 quick test with input and output parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
url = "https://judge0-ce.p.rapidapi.com/submissions" | |
rapidapi_key = "I'll whatsapp you" | |
querystring = {"base64_encoded":"true","fields":"*"} | |
payload = { | |
"language_id": 52, | |
"source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBuYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxvLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=", # takes string from stdin, prints "Hello, <string>" | |
"stdin": "SnVkZ2Uw", # Judge0 | |
"expected_output": "aGVsbG8sIEp1ZGdlMAo=", # hello, Judge0 | |
} | |
headers = { | |
"content-type": "application/json", | |
"Content-Type": "application/json", | |
"X-RapidAPI-Key": rapidapi_key, | |
"X-RapidAPI-Host": "judge0-ce.p.rapidapi.com" | |
} | |
response = requests.request("POST", url, json=payload, headers=headers, params=querystring) | |
print(response.text) | |
""" | |
{"token":"471b940e-75e1-4703-a831-b71cadf3bb01"} | |
""" | |
# check status | |
url = "https://judge0-ce.p.rapidapi.com/submissions/471b940e-75e1-4703-a831-b71cadf3bb01" | |
querystring = {"base64_encoded":"true","fields":"*"} | |
headers = { | |
"X-RapidAPI-Key": rapidapi_key, | |
"X-RapidAPI-Host": "judge0-ce.p.rapidapi.com" | |
} | |
response = requests.request("GET", url, headers=headers, params=querystring) | |
print(response.text) | |
""" | |
{ | |
"source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBu\nYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxv\nLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=\n", | |
"language_id": 52, | |
"stdin": "SnVkZ2Uw\n", | |
"expected_output": "aGVsbG8sIEp1ZGdlMAo=\n", | |
"stdout": "aGVsbG8sIEp1ZGdlMAo=\n", | |
"status_id": 3, | |
"created_at": "2022-07-07T02:39:00.962Z", | |
"finished_at": "2022-07-07T02:39:07.049Z", | |
"time": "0.005", | |
"memory": 1088, | |
"stderr": null, | |
"token": "471b940e-75e1-4703-a831-b71cadf3bb01", | |
"number_of_runs": 1, | |
"cpu_time_limit": "5.0", | |
"cpu_extra_time": "1.0", | |
"wall_time_limit": "10.0", | |
"memory_limit": 128000, | |
"stack_limit": 64000, | |
"max_processes_and_or_threads": 60, | |
"enable_per_process_and_thread_time_limit": false, | |
"enable_per_process_and_thread_memory_limit": false, | |
"max_file_size": 1024, | |
"compile_output": null, | |
"exit_code": 0, | |
"exit_signal": null, | |
"message": null, | |
"wall_time": "0.032", | |
"compiler_options": null, | |
"command_line_arguments": null, | |
"redirect_stderr_to_stdout": false, | |
"callback_url": null, | |
"additional_files": null, | |
"enable_network": false, | |
"status": { | |
"id": 3, | |
"description": "Accepted" | |
}, | |
"language": { | |
"id": 52, | |
"name": "C++ (GCC 7.4.0)" | |
} | |
} | |
""" | |
url = "https://judge0-ce.p.rapidapi.com/submissions" | |
querystring = {"base64_encoded":"true","fields":"*"} | |
payload = { | |
"language_id": 52, | |
"source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBuYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxvLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=", # takes string from stdin, prints "Hello, <string>" | |
"stdin": "QmFkcmk=", # Badri | |
"expected_output": "aGVsbG8sIEp1ZGdlMAo=", # hello, Judge0 | |
} | |
headers = { | |
"content-type": "application/json", | |
"Content-Type": "application/json", | |
"X-RapidAPI-Key": rapidapi_key, | |
"X-RapidAPI-Host": "judge0-ce.p.rapidapi.com" | |
} | |
response = requests.request("POST", url, json=payload, headers=headers, params=querystring) | |
print(response.json()) | |
""" | |
{"token":"7738bd30-8832-4c1a-8827-f60e004dccf6"} | |
""" | |
# check status | |
url = "https://judge0-ce.p.rapidapi.com/submissions/7738bd30-8832-4c1a-8827-f60e004dccf6" | |
querystring = {"base64_encoded":"true","fields":"*"} | |
headers = { | |
"X-RapidAPI-Key": rapidapi_key, | |
"X-RapidAPI-Host": "judge0-ce.p.rapidapi.com" | |
} | |
response = requests.request("GET", url, headers=headers, params=querystring) | |
print(response.text) | |
""" | |
{ | |
"source_code": "I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgY2hhciBu\nYW1lWzEwXTsKICBzY2FuZigiJXMiLCBuYW1lKTsKICBwcmludGYoImhlbGxv\nLCAlc1xuIiwgbmFtZSk7CiAgcmV0dXJuIDA7Cn0=\n", | |
"language_id": 52, | |
"stdin": "QmFkcmk=\n", | |
"expected_output": "aGVsbG8sIEp1ZGdlMAo=\n", | |
"stdout": "aGVsbG8sIEJhZHJpCg==\n", | |
"status_id": 4, | |
"created_at": "2022-07-07T03:27:38.223Z", | |
"finished_at": "2022-07-07T03:27:43.983Z", | |
"time": "0.002", | |
"memory": 796, | |
"stderr": null, | |
"token": "7738bd30-8832-4c1a-8827-f60e004dccf6", | |
"number_of_runs": 1, | |
"cpu_time_limit": "5.0", | |
"cpu_extra_time": "1.0", | |
"wall_time_limit": "10.0", | |
"memory_limit": 128000, | |
"stack_limit": 64000, | |
"max_processes_and_or_threads": 60, | |
"enable_per_process_and_thread_time_limit": false, | |
"enable_per_process_and_thread_memory_limit": false, | |
"max_file_size": 1024, | |
"compile_output": null, | |
"exit_code": 0, | |
"exit_signal": null, | |
"message": null, | |
"wall_time": "0.045", | |
"compiler_options": null, | |
"command_line_arguments": null, | |
"redirect_stderr_to_stdout": false, | |
"callback_url": null, | |
"additional_files": null, | |
"enable_network": false, | |
"status": { | |
"id": 4, | |
"description": "Wrong Answer" | |
}, | |
"language": { | |
"id": 52, | |
"name": "C++ (GCC 7.4.0)" | |
} | |
} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment