コード例 #1
0
ファイル: test.py プロジェクト: rucamedia/python-client
"""
Example presents usage of the successful test() API method
"""
from sphere_engine import CompilersClientV4

# define access parameters
accessToken = '<access_token>'
endpoint = '<endpoint>'

# initialization
client = CompilersClientV4(accessToken, endpoint)

# API usage
response = client.test()
コード例 #2
0
 def setUp(self):
     self.client = CompilersClientV4('access-token', 'endpoint')
コード例 #3
0
ファイル: gc_func_compiler.py プロジェクト: ayung8/CodeBoard
def hello_world(request):

    # define access parameters
    accessToken = '77501c36922866a03b1822b4508a50c6'
    endpoint = 'dd57039c.compilers.sphere-engine.com'

    # initialization
    client = CompilersClientV4(accessToken, endpoint)

    # API usage
    # source = 'function f() {return "hello"; } print(f());' # Javascript
    # compiler = 112 # Javascript

    # source = 'print("hello world please work!!!!!")' # Python

    # extract text from json and assign to source
    request_json = request.get_json()
    cource = request.args.get('message')

    compiler = 116  # Python

    input = '2017'

    # Set default value for response
    response = None

    # Sends the submission and checks for errors in sending the submission
    try:
        response = client.submissions.create(source, compiler, input)
        # response['id'] stores the ID of the created submission
    except SphereEngineException as e:
        if e.code == 401:
            print('Invalid access token')
        elif e.code == 402:
            print('Unable to create submission')
        elif e.code == 400:
            print('Error code: ' + str(e.error_code) +
                  ', details available in the message: ' + str(e))

    # Set default value for response data
    responseData = None

    print("Code submitted is: ")
    print(source)
    print("Submission ID is: " + str(response.get('id')))
    print()

    # Try getting submission ID and check if there are errors
    try:
        client.submissions.get(response.get('id'))
    except SphereEngineException as e:
        if e.code == 401:
            print('Invalid access token')
        elif e.code == 403:
            print('Access to the submission is forbidden')
        elif e.code == 404:
            print('Submission does not exist')

    # Uses submission ID, and checks every x seconds to see if query has been 'accepted' (finished processing)
    while client.submissions.get(response.get('id')).get('result').get(
            'status').get('name') != 'accepted':
        responseData = client.submissions.get(response.get('id'))
        print(responseData)  # for test purposes
        print("Status is: " +
              responseData.get('result').get('status').get('name'))
        time.sleep(5)

    print("Status is: " + client.submissions.get(response.get('id')).get(
        'result').get('status').get('name'))
    print()

    rawresponse = None

    # Get the output of the query
    try:
        rawresponse = client.submissions.getStream(response.get('id'),
                                                   'output')
    except SphereEngineException as e:
        if e.code == 401:
            print('Invalid access token')
        elif e.code == 403:
            print('Access to the submission is forbidden')
        elif e.code == 404:
            print('Non existing resource, error code: ' + str(e.error_code) +
                  ', details available in the message: ' + str(e))
        elif e.code == 400:
            print('Error code: ' + str(e.error_code) +
                  ', details available in the message: ' + str(e))

    #print("Output returned is: ")
    #print(rawresponse)

    return (rawresponse)
コード例 #4
0
def compileCode(code, language = "javascript") :
    # define access parameters
    accessToken = '77501c36922866a03b1822b4508a50c6'
    endpoint = 'dd57039c.compilers.sphere-engine.com'

    # initialization
    client = CompilersClientV4(accessToken, endpoint)

    # API usage

    if language == "python" :
        #source = 'print("hello world please work!!!!!")'  # Python
        source = '' + str(code)
        compiler = 116  # Python

    elif language == "c" :

        source = '' + str(code)
        compiler = 11  # C

    elif language == "javascript":
        # source = 'function f() {return "hello"; } print(f());' # Javascript
        source = '' + str(code)
        compiler = 112  # Javascript

    else :
        #source = 'function f() {return "hello"; } print(f());' # Javascript
        source = '' + str(code)
        compiler = 112 # Javascript

    input = 'none'

    # Set default value for response
    response = None

    # Sends the submission and checks for errors in sending the submission
    try:
        response = client.submissions.create(source, compiler, input)
        # response['id'] stores the ID of the created submission
    except SphereEngineException as e:
        if e.code == 401:
            print('Invalid access token')
        elif e.code == 402:
            print('Unable to create submission')
        elif e.code == 400:
            print('Error code: ' + str(e.error_code) + ', details available in the message: ' + str(e))

    # Set default value for response data
    responseData = None

    print("Code submitted is: ")
    print(source)
    print("Submission ID is: " + str(response.get('id')))
    print()

    # Try getting submission ID and check if there are errors
    try:
        client.submissions.get(response.get('id'))
    except SphereEngineException as e:
        if e.code == 401:
            print('Invalid access token')
        elif e.code == 403:
            print('Access to the submission is forbidden')
        elif e.code == 404:
            print('Submission does not exist')

    # Uses submission ID, and checks every x seconds to see if query has been 'accepted' (finished processing)
    while client.submissions.get(response.get('id')).get('result').get('status').get('name') != 'accepted':

        # Shortcircuit function:
        if client.submissions.get(response.get('id')).get('result').get('status').get('name') == 'runtime error' :
            print("ERROR: Runtime Error")
            return 'ERROR: Runtime Error'

        if client.submissions.get(response.get('id')).get('result').get('status').get('name') == 'compilation error' :
            print("ERROR: Compilation Error")
            return 'ERROR: Compilation Error'

        responseData = client.submissions.get(response.get('id'))
        print(responseData)  # for test purposes
        print("Status is: " + responseData.get('result').get('status').get('name'))
        time.sleep(5)

    print("Status is: " + client.submissions.get(response.get('id')).get('result').get('status').get('name'))
    print()

    rawresponse = None

    # Get the output of the query
    try:
        rawresponse = client.submissions.getStream(response.get('id'), 'output')
    except SphereEngineException as e:
        if e.code == 401:
            print('Invalid access token')
        elif e.code == 403:
            print('Access to the submission is forbidden')
        elif e.code == 404:
            print('Non existing resource, error code: ' + str(
                e.error_code) + ', details available in the message: ' + str(e))
        elif e.code == 400:
            print('Error code: ' + str(e.error_code) + ', details available in the message: ' + str(e))

    print("Output returned is: ")
    print(rawresponse)

    return rawresponse
コード例 #5
0
ファイル: main.py プロジェクト: richie312/Online-Compiler
problem_accessToken = problem_auth['token']
problem_endpoint = problem_auth['endpoint']

client = ProblemsClientV4(problem_accessToken, problem_endpoint)

### Compiler API
compiler_auth = {
    "endpoint": "b47c8916.compilers.sphere-engine.com",
    "token": "6fc402f585b35ef7accf61facc636af0"
}

# define access parameters
compiler_accessToken = compiler_auth["token"]
compiler_endpoint = compiler_auth["endpoint"]

compiler_client = CompilersClientV4(compiler_accessToken, compiler_endpoint)

# Problem API initialization
try:
    response_problem_api = client.test()
except SphereEngineException as e:
    if e.code == 401:
        print('Invalid access token')

# compiler Api initialization

try:
    compiler_response = compiler_client.test()
except SphereEngineException as e:
    if e.code == 401:
        print('Invalid access token')