-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.py
More file actions
34 lines (25 loc) · 898 Bytes
/
upload.py
File metadata and controls
34 lines (25 loc) · 898 Bytes
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
import glob
import os
from google.cloud import storage
def upload():
cred_file = 'data/YAWN-service-account.json'
if os.path.exists(cred_file):
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = cred_file
public_url = os.environ['PUBLIC_URL'].strip('/')
client = storage.Client()
bucket = client.bucket('static.yawn.live')
existing = bucket.list_blobs(prefix=public_url)
bucket.delete_blobs(existing)
for filename in glob.glob('build/**', recursive=True):
if os.path.isdir(filename):
continue
path = f'{public_url}/{filename.replace("build/", "")}'
print(f'Uploading {path}')
blob = bucket.blob(path)
blob.upload_from_filename(filename)
blob.make_public()
print('')
print(f'View the site at http://static.yawn.live/{public_url}/')
print('')
if __name__ == '__main__':
upload()