-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinalhiveASP
57 lines (46 loc) · 1.51 KB
/
FinalhiveASP
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
import functions_framework
import json
from google.cloud import storage
# Triggered by a change in a storage bucket
@functions_framework.cloud_event
def userVals(cloud_event):
def writeToASP(bucketName,vals, name):
print(vals)
storageClient=storage.Client()
bucket=storageClient.bucket(bucketName)
blob= bucket.blob(name)
blob.content_type="application/json"
with blob.open(mode="w") as f:
f.write(vals)
data = cloud_event.data
event_id = cloud_event["id"]
event_type = cloud_event["type"]
bucket = data["bucket"]
name = data["name"]
metageneration = data["metageneration"]
timeCreated = data["timeCreated"]
updated = data["updated"]
print(f"Event ID: {event_id}")
print(f"Event type: {event_type}")
print(f"Bucket: {bucket}")
print(f"File: {name}")
print(f"Metageneration: {metageneration}")
print(f"Created: {timeCreated}")
print(f"Updated: {updated}")
storageClient=storage.Client()
bucket = storageClient.get_bucket(bucket)
blob=bucket.blob(name)
blobBytes=blob.download_as_bytes()
blobString= blobBytes.decode("utf-8")
blobByteJson = blob.download_as_bytes().decode()
userVals= json.loads(blobByteJson)
currHiveID = userVals['hiveID']
print(currHiveID)
print(name)
if name == currHiveID:
return
else:
writeToASP("asp_react",blobString,name)
#Requirements file
#functions-framework==3.*
#google-cloud-storage