from __future__ import ( print_function, ) # Ensure print() function is available in Python 2 import sys import json import requests import base64 from Deadline.Scripting import * # type: ignore # Import Deadline script utilities api_path = "https://canvas-api-test.anvil.app/_/api" # def update_3d_image_task_status(row_id, new_status): # # Define the URL for the API endpoint # url = "{}/tasks/3d-image/update-status".format(api_path) # # Create a JSON payload # payload = {"row_id": row_id, "new_status": new_status} # # Make a POST request to the API endpoint with the JSON payload # response = requests.post(url, json=payload) # # Handle the response # if response.status_code == 200: # print("Status update was successful") # return response.json() # else: # print("Status update failed") # print("Status code:", response.status_code) # print("Response:", response.text) # return None # def get_3d_image_task(row_id): # # Define the URL for the API endpoint # url = "{}/tasks/3d-image/{}".format(api_path, row_id) # print("Constructed URL:", url) # Print the URL for debugging # # Make a GET request to the API endpoint # response = requests.get(url) # # Handle the response # if response.status_code == 200: # print("Request was successful") # return response.json() # else: # print("Request failed") # print("Status code:", response.status_code) # print("Response:", response.text) # return None # def find_image_and_convert_to_base64(image_path): # with open(image_path, "rb") as image_file: # image_data = image_file.read() # image_base64 = base64.b64encode(image_data).decode("utf-8") # return image_base64 # def upload_image_to_anvil(row_id, image_base64): # url = "{}/test-2".format(api_path) # payload = {"row_id": row_id, "image_base64": image_base64} # response = requests.post(url, json=payload) # if response.status_code == 200: # print("Image uploaded successfully") # update_3d_image_task_status(row_id=row_id, new_status=3) # return response.json() # else: # print("Image upload failed") # print("Status code:", response.status_code) # print("Response:", response.text) # return None def __main__(*args): deadlinePlugin = args[0] job = deadlinePlugin.GetJob() print("AI image completed") # row_id = job.JobExtraInfo0 # response = get_3d_image_task(row_id) # data = json.loads(response["data"]) # project_id = data["project_id"] # image_base64 = find_image_and_convert_to_base64( # image_path + "{}/base0001.jpg".format(project_id) # ) # upload_image_to_anvil(row_id, image_base64) if __name__ == "__main__": __main__(sys.argv)