Demo entry 6365294

test

   

Submitted by anonymous on May 18, 2017 at 17:30
Language: Python. Code size: 1.6 kB.

import json
import logging
from kosa_decoder.pipeline import get_full_aws_pipeline, new_item_from_image_base64

pipeline = get_full_aws_pipeline()

# logger = logging.getLogger()
# if logger.handlers:
#     for handler in logger.handlers:
#         logger.removeHandler(handler)
# logging.basicConfig(format='%(asctime)s %(message)s',level=logging.DEBUG)



# logger.setLevel(logging.INFO)


LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

def lambda_handler(event, context):
    print('Handling event...')
    LOGGER.info('got event')
    LOGGER.error('something went wrong')
    LOGGER.debug('debugging')

    image = event.get('body-json', '')

    if not image:
        print('No image to process')
        return json.dumps({'value': ''})
    
    # try:
    #     print('Instantiating item...')
    #     item = new_item_from_image_base64(image)
    #     print('Pushing item to pipeline...')
    #     pipeline.push(item)
    #     print('Item was processed...')
    # except:
    #     print('Could not decode item')
    # finally:        
    #     print('item.code: ', item.code)    
    #     response = json.dumps({'value': item.code})        
    #     return response

    print('Instantiating item...')
    item = new_item_from_image_base64(image)
    print('Pushing item to pipeline...')
    pipeline.push(item)
    print('Item was processed...')
    print('item.code: ', item.code)
    response = '{"value": %s}' % item.code
    print('response: ', response)
    #response = str(json.dumps({'value': item.code}))
    response = {'value': item.code}
    return response

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).