示例#1
0
def lambda_handler(event, context):

    email_id = event["email_id"]
    names = qs.process_messages_from_queue()
    names = list(names)
    print('from queue....', names)
    '''
    email_id = 'test'
    names = ['Joby_Joy']
    temp = {
        'pm2696':'Pranav_Reddy'
    }
    es.index(index="students", doc_type="_doc", id="500", body=temp)
    print(es.get(index="students", doc_type="_doc", id="500"))
    '''
    es = data_index.connect_to_elastic_search()
    records = data_index.search_student_records(es, names)
    print('from elastic search..', records)

    ns.publish_report(records, email_id)

    result = "Email sent successfully to {}. Please check your inbox.".format(
        email_id)
    return {
        'statusCode': str(200),
        'results': result,
        'headers': {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*'
        },
    }
示例#2
0
def lambda_handler(event, context):
    print(event)
    query = event['currentIntent']['slots']['searchque']
    print('query', query)

    keys = query.split(',')
    Res = []
    es = data_index.connect_to_elastic_search()
    out = []
    outS = ""
    outRes = []
    for i in range(len(keys)):
        print(keys[i])
        res = es.search(q=keys[i])
        Res.append(res)
        print("Got %d Hits:" % res['hits']['total'])
        print(res)
        for i in res['hits']['hits']:
            bucket = i['_source']['bucket']
            image = i['_source']['objectKey']
            a = "https://s3.amazonaws.com/" + bucket + "/" + image
            if a not in out:
                out.append(a)
                outS += a + ", "
                outRes.append({
                    'title': image.split(".")[0],
                    'attachmentLinkUrl': a,
                    'imageUrl': a
                })
        print('File path: ', out)

    result = {
        "dialogAction": {
            "type": "Close",
            "fulfillmentState": "Fulfilled",
            "message": {
                "contentType": "PlainText",
                "content": outS
            },
            "responseCard": {
                'version': '0',
                'contentType': 'application/vnd.amazonaws.card.generic',
                'genericAttachments': outRes
            }
        }
    }
    return result
def lambda_handler(event, context):
    print(event)
    label_list = []

    for record in event['Records']:
        PHOTO_BUCKET = record['s3']['bucket']['name']
        FILE_NAME = record['s3']['object']['key']

    print('reading image: {} from s3 bucket {}'.format(FILE_NAME,
                                                       PHOTO_BUCKET))
    client = boto3.client('rekognition')
    response = client.detect_labels(
        Image={'S3Object': {
            'Bucket': PHOTO_BUCKET,
            'Name': FILE_NAME
        }},
        MaxLabels=12,
        MinConfidence=80,
    )

    print('Detected labels for ' + FILE_NAME)
    for label in response['Labels']:
        print(label['Name'] + ' : ' + str(label['Confidence']))
        label_list.append(label['Name'])

    ts = time.gmtime()
    created_time = time.strftime("%Y-%m-%dT%H:%M:%S", ts)
    print('Image created at {}....'.format(created_time))

    image_object = {
        'objectKey': FILE_NAME,
        'bucket': PHOTO_BUCKET,
        'createdTimestamp': created_time,
        'labels': label_list
    }

    es = data_index.connect_to_elastic_search()
    es.index(index="photos",
             doc_type="_doc",
             id=created_time,
             body=image_object)

    response = es.get(index="photos", doc_type="_doc", id=created_time)

    return response
示例#4
0
def lambda_handler(event, context):
    query = event['query']['q']
    #query = 'show me flowers and dogs'
    sessionAttributes = {}
    response = lex_client.post_text(botName="SearchPhotos",
                                    botAlias="SearchPhotos",
                                    userId="test",
                                    sessionAttributes=sessionAttributes,
                                    inputText=query)
    print(response['message'])
    search_query = response['message']
    #search_query = 'cat,flower'

    keys = search_query.split(',')
    result = []
    resp = {}

    #resp['statusCode'] = str(200)
    es = data_index.connect_to_elastic_search()

    for i in range(len(keys)):

        if keys[i].endswith('s'):
            length = len(keys[i]) - 1
            keys[i] = keys[i][0:length]
            print(keys[i])

        res = es.search(q=keys[i])
        result = create_image_objects(res['hits']['hits'], result)

    resp['results'] = result

    return {
        'statusCode': str(200),
        'results': result,
        'headers': {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*'
        },
    }