def DoTask(task):
  """Load, process and upload task image and return processed image link."""

  payload = json.loads(base64.b64decode(task['payloadBase64']))

  # Load Image from URL
  url = payload['image_link']

  # Save image temporarily for upload with timestamp as name
  filename = '%s_%s' % (url[url.rfind('/')+1:],
                        datetime.strftime(datetime.now(),
                                          '%Y_%M_%d_%H_%M_%S_%s'))

  filepath = os.path.join('/tmp', filename)

  # Save image to temporary file
  try:
    image_request = urllib2.urlopen(url)
    with open(filepath, 'wb') as file_handle:
      file_handle.write(image_request.read())
  except urllib2.HTTPError, e:
    logging.error('Error loading image link %s : %s', url, e)
    return False

  # Generate Bitified image from given image.
  try:
    processed_image = ConvertToBitifiedImage(filepath)
  except IOError, e:
    logging.error('Error processing image for %s : %s', url, e)
    return False

  filepath_processed_image = filepath+'.png'

  try:
    processed_image.save(filepath_processed_image)
  except __HOLE__, e:
    logging.error('Error saving processed image for %s : %s', url, e)
    return False

  # Upload processed image to bitified image cloud bucket
  contents = file(filepath_processed_image, 'r')
  uri = boto.storage_uri(settings.PROCESSED_IMG_BUCKET + '/' + filename,
                         settings.GOOGLE_STORAGE)
  uri.new_key().set_contents_from_file(contents)

  contents.close()

  # Remove temporary image
  os.remove(filepath)

  logging.info('%s - Successfully created "%s/%s"\n',
               datetime.now(),
               uri.bucket_name,
               uri.object_name)

  return uri.object_name
dataset/ETHPy150Open GoogleCloudPlatform/solutions-orchestrator-android-sampleapp-smashpix/daemon/compute_engine_daemon.py/DoTask