-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgcc_top_pools.py
55 lines (37 loc) · 1.33 KB
/
gcc_top_pools.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
"""
This file is used for Google Cloud functions to update the top pools in the last 24 hours
"""
import json
from top_pools_base import top_pools_base
from gcc_utils import gccPrint, get_event_id, get_google_cloud_storage_blob
# Output file name
FILE_NAME = "pools.json"
# Google Cloud Storage
TRISOLARIS_BUCKET = "trisolaris_public"
TRISOLARIS_BUCKET_FILE_PATH = FILE_NAME
TAG = "[GCC_TOP_POOLS]"
# Gets fee data from covalent api
# Uploads result to gcc file storage
def gcc_top_pools(data, context):
event_id = get_event_id(context)
gccPrint(
f"{TAG} Beginning Google Cloud Fn processing of top pools for event_id: {event_id}"
)
result = top_pools_base()
if len(result) == 0:
gccPrint(f"{TAG} Received 0 items, not uploading to GCC")
return
blob = get_google_cloud_storage_blob(TRISOLARIS_BUCKET, TRISOLARIS_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()
gccPrint(
f"{TAG} Uploading to gcc location: {TRISOLARIS_BUCKET}/{TRISOLARIS_BUCKET_FILE_PATH} complete"
)
if __name__ == "__main__":
gcc_top_pools(None, None)