-
Notifications
You must be signed in to change notification settings - Fork 1
/
task_checker.py
76 lines (59 loc) · 2.5 KB
/
task_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import boto3
import json
#import blink_things
from tasks import *
client = boto3.client('rekognition')
def check_task (task_id, refPicPath, livePicsPath):
# print('--- Authenticating ---')
#if not blink_things.user_blinked(livePics):
# return False
task_checker = task_dict[task_id]
print("Running task checker:", task_arg_dict[task_id])
return task_checker(client, task_arg_dict[task_id], livePicsPath, refPicPath)
def respond(auth, err):
return {
'statusCode': '400' if err else '200',
'body': err.message if err else json.dumps(auth),
'headers': {
'Content-Type': 'application/json',
},
}
def lambda_handler(event, context):
if event['httpMethod'] == 'POST':
body = json.loads(event['body'])
taskId = body['taskId']
refPicPath = body['username'] + '.png'
livePicsPath = body['livePicPath']
print('Ref:',refPicPath,'Live:',livePicsPath)
auth = check_task(taskId, refPicPath, livePicsPath)
return respond(auth, None)
else:
return respond(None, {'message':'This endpoint only accepts POST requests!'})
if __name__ == "__main__":
ref_aneek = '[email protected]'
ref_manny = '[email protected]'
shoe_left='shoe_left.jpg'
shoe_left_new='fa5nf6kxl6.png'
shoe_right_new='q2j0llfu81.png'
shoe_right = 'shoe_right.jpg'
flip_flop_right='flip_flop_right.jpg'
cup = 'cup.jpg'
beverage = 'bev.jpg'
bottle = 'bot.jpg'
finger = 'finger.jpg'
toy_left = 'toy_left.jpg'
toy_right = 'toy_right.jpg'
assert(check_task(0, ref_manny, 'face1.jpg')['res']) # always_true
assert(check_task(1, ref_aneek, shoe_left_new)['res']) # shoe_left
assert(check_task(2, ref_aneek, flip_flop_right)['res']) # flip_flop_right
assert(not check_task(2, ref_manny, shoe_right_new)['res']) # shoe_left failure
assert(not check_task(2, ref_manny, flip_flop_right)['res']) # flip_flop_right failure
assert(check_task(3, ref_manny, cup)['res']) # cup
assert(check_task(4, ref_manny, beverage)['res']) # beverage
assert(check_task(5, ref_manny, bottle)['res']) # bottle
assert(check_task(6, ref_manny, finger)['res']) # finger
assert(check_task(7, ref_aneek, shoe_right_new)['res']) # shoe_right
assert(check_task(9, ref_aneek, toy_left)['res']) # toy_left
assert(check_task(10, ref_aneek, toy_right)['res']) # toy_right
assert(not check_task(9, ref_aneek, toy_right)['res']) # toy_right failure
print("all tests passed!!")