/
handler.py
52 lines (39 loc) · 1.44 KB
/
handler.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
import json
import requests
import logging
import pprint
import boto3
from datetime import datetime, timedelta
from mail import sendmail
log = logging.getLogger("COVID")
def covid(event, context):
resp = requests.get(
'https://data.ontario.ca/api/3/action/datastore_search?resource_id=8b6d22e2-7065-4b0f-966f-02640be366f2&limit=50&filters={"reported_date":"2020-10-16T00:00:00","school_board":"Peel District School Board"}'
)
body = resp.json()
log.info(body)
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
# Use this code if you don't use the http event with the LAMBDA-PROXY
# integration
def notify(event, context):
yesterday = datetime.strftime(datetime.now() - timedelta(1), '%Y-%m-%d')
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table('school-covid19-notify')
response = table.scan()
data_items = response['Items']
for item in data_items:
resp = requests.get(
'https://data.ontario.ca/api/3/action/datastore_search?resource_id=8b6d22e2-7065-4b0f-966f-02640be366f2'
'&limit=800'
'&filters={"school_board":"Peel District School Board","reported_date":"%s", "school":"%s"}'
% (yesterday, item["school"])
)
if resp.json()["result"]["records"]:
sendmail(item["email"], item["school"])
# if __name__ == "__main__":
# # pprint.pprint(covid({}, {}))
#