def get_batch_job(project_id, batch_id, x_api_key,next_page_token):
base_url = "https://api.playment.io/v1/projects/{}/batch/{}?page_token={}".format(
project_id, batch_id, next_page_token
headers = {"x-api-key": x_api_key}
response = requests.get(base_url, headers=headers)
if response.status_code >= 500:
raise Exception(response.text)
if 400 <= response.status_code < 500:
raise Exception(response.text)
def get_job_result(project_id,job_id, x_api_key):
base_url = "https://api.playment.io/v1/projects/{}/jobs/{}".format(project_id,job_id)
headers = {"x-api-key": x_api_key}
response = requests.get(base_url, headers=headers)
if response.status_code >= 500:
raise Exception(response.text)
if 400 <= response.status_code < 500:
raise Exception(response.text)
def get_attachment(result_url, x_api_key):
base_url = "https://api.playment.io/v1/attachments?url={}".format(result_url)
headers = {"x-api-key": x_api_key}
response = requests.get(base_url, headers=headers)
if response.status_code >= 500:
raise Exception(response.text)
if 400 <= response.status_code < 500:
raise Exception(response.text)
if __name__ == "__main__":
batch_res = get_batch_job(project_id, batch_id, x_api_key,'')
jobs = batch_res['data']['jobs']
while 'next_page_token' in batch_res['data'].keys():
next_page_token = batch_res['data']['next_page_token']
batch_res = get_batch_job(project_id, batch_id, x_api_key,next_page_token)
jobs = jobs + batch_res['data']['jobs']
# Set the desired folder struture/name here
job_res = get_job_result(project_id,job['id'],x_api_key)
job_annotation_result = get_attachment(job_res['data']['result'],x_api_key)
file_name = job['id'] + '.json'
with open(os.path.join(folder_name, file_name),'w') as outfile:
json.dump(job_annotation_result, outfile)