-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgcc_apr.py
48 lines (31 loc) · 1.22 KB
/
gcc_apr.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
"""
This file is used for Google Cloud functions to serve apr calculations
"""
import json
from apr_base import apr_base
from gcc_utils import (get_event_id, get_google_cloud_storage_blob)
# Output file name
FILE_NAME = "datav2.json"
# Google Cloud Storage
TRISOLARIS_APR_BUCKET = "trisolaris_public"
TRISOLARIS_APR_BUCKET_FILE_PATH = FILE_NAME
TAG = "[GCC_APR]"
# Gets apr data from `apr_base`
# Uploads result to gcc file storage
def gcc_apr(data, context):
event_id = get_event_id(context)
print(TAG + "Beginning Google Cloud Fn processing of apr for event_id: {0}".format(event_id))
result = apr_base()
print(TAG + "APR calculation completed")
blob = get_google_cloud_storage_blob(TRISOLARIS_APR_BUCKET, TRISOLARIS_APR_BUCKET_FILE_PATH)
json_data = json.dumps(result, ensure_ascii=False, indent=4)
blob.upload_from_string(json_data, "application/json")
# Don't serve stale data
blob.cache_control = 'no-cache'
# Allows file to be publicly accessible
blob.make_public()
# Save
blob.patch()
print(TAG + "Uploading to gcc location: {0}/{1} complete".format(TRISOLARIS_APR_BUCKET, TRISOLARIS_APR_BUCKET_FILE_PATH))
if __name__ == "__main__":
gcc_apr(None, None)