Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
svdgraaf committed Jan 19, 2018
1 parent ee4e800 commit 790f915
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 38 deletions.
62 changes: 30 additions & 32 deletions doorman/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ functions:
- http:
path: faces/train
method: post
environment:
DELETE_FUNCTION_ARN:
Ref: DeleteLambdaFunction

delete:
handler: handler.delete

# resources:
# Resources:
Expand Down

0 comments on commit 790f915

Please sign in to comment.