diff --git a/doorman/train.py b/doorman/train.py index d768f1b..18029c2 100644 --- a/doorman/train.py +++ b/doorman/train.py @@ -12,31 +12,34 @@ def train(event, context): - # client = boto3.client('rekognition') - # resp = client.index_faces() - print(event['body']) + # print(event['body']) data = parse_qs(event['body']) data = json.loads(data['payload'][0]) - + print(data) key = data['callback_id'] # if we got a discard action, send an update first, and then remove the referenced image if data['actions'][0]['name'] == 'discard': message = { - "statusCode": 200, - "body": json.dumps({ - "text": "Ok, I ignored this image", - "attachments": [ - { - "image_url": "https://s3.amazonaws.com/%s/%s" % (bucket_name, key), - "fallback": "Nope?", - "attachment_type": "default", - } - ] - }) + "text": "Ok, I ignored this image", + "attachments": [ + { + "image_url": "https://s3.amazonaws.com/%s/%s" % (bucket_name, key), + "fallback": "Nope?", + "attachment_type": "default", + } + ] } + print(message) - requests.post(data['response_url'], headers={'Content-Type':'application/json;charset=UTF-8', 'Authorization': 'Bearer %s' % slack_token}, json=message) + requests.post( + data['response_url'], + headers={ + 'Content-Type':'application/json;charset=UTF-8', + 'Authorization': 'Bearer %s' % slack_token + }, + json=message + ) s3 = boto3.resource('s3') s3.Object(bucket_name, key).delete() @@ -46,17 +49,14 @@ def train(event, context): new_key = 'trained/%s/%s.jpg' % (user_id, hashlib.md5(key.encode('utf-8')).hexdigest()) message = { - "statusCode": 200, - "body": json.dumps({ - "text": "Trained as %s" % user_id, - "attachments": [ - { - "image_url": "https://s3.amazonaws.com/%s/%s" % (bucket_name, new_key), - "fallback": "Nope?", - "attachment_type": "default", - } - ] - }) + "text": "Trained as %s" % user_id, + "attachments": [ + { + "image_url": "https://s3.amazonaws.com/%s/%s" % (bucket_name, new_key), + "fallback": "Nope?", + "attachment_type": "default", + } + ] } print(message) requests.post(data['response_url'], headers={'Content-Type':'application/json;charset=UTF-8', 'Authorization': 'Bearer %s' % slack_token}, json=message) @@ -76,13 +76,11 @@ def train(event, context): ) # move the s3 file to the 'trained' location - print (key) - print (new_key) s3 = boto3.resource('s3') s3.Object(bucket_name, new_key).copy_from(CopySource='%s/%s' % (bucket_name, key)) s3.ObjectAcl(bucket_name, new_key).put(ACL='public-read') s3.Object(bucket_name, key).delete() - print (foo.json()) - - return {} + return { + "statusCode": 200 + } diff --git a/readme.md b/readme.md index f9706af..05c4945 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,4 @@ aws rekognition create-collection --collection-id sentia + + + 1203 ggc_user 20 0 82664 34704 7640 S 0.3 0.4 0:02.68 python2.7 /runtime/python2.7/lambda_runtime.py --handler=das_mutter.function_handler diff --git a/serverless.yml b/serverless.yml index 3d62aa0..1300a79 100644 --- a/serverless.yml +++ b/serverless.yml @@ -91,12 +91,6 @@ functions: - http: path: faces/train method: post - environment: - DELETE_FUNCTION_ARN: - Ref: DeleteLambdaFunction - - delete: - handler: handler.delete # resources: # Resources: