-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
49 lines (36 loc) · 1.08 KB
/
lambda_function.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
import json
from datetime import datetime, timedelta
import requests
import json
with open('config.json') as f:
conf = json.load(f)
url = 'https://api-{}.scorer.jp/v1/devices/{}/vcajobs'.format(
conf.realm, conf.device_id)
headers = {
'Authorization': conf.api_key,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
payload = {
'algorithmId': conf.algorithm_id,
'algorithmVersion': '1.0',
'arguments': {
'fromDateTime': None,
'toDateTime': None
},
'jobType': 'Period'
}
def lambda_handler(event, context):
current_dt = datetime.today()
end_dt = current_dt.replace(minute=0, second=0, microsecond=0)
end_str = end_dt.strftime('%Y-%m-%d %H:%M:%S+0900')
start_dt = end_dt - timedelta(hours=1)
start_str = start_dt.strftime('%Y-%m-%d %H:%M:%S+0900')
payload['arguments']['fromDateTime'] = start_str
payload['arguments']['toDateTime'] = end_str
try:
res = requests.post(url, data=payload, headers=headers)
return res
except Exception as e:
print(e)
raise e