-
Notifications
You must be signed in to change notification settings - Fork 4
/
upload_html_to_bucket.py
42 lines (38 loc) · 1.53 KB
/
upload_html_to_bucket.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
import datetime
from google.cloud import storage
import os
import glob
def upload_to_storage(local_path, bucket_name, blob_name):
with open(local_path, 'rb') as fh:
client = storage.Client()
bucket = client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.upload_from_file(fh, content_type = 'text/html')
blob.cache_control = 'public, max-age=60'
blob.patch()
def upload_to_storage_(s, bucket_name, blob_name):
client = storage.Client()
bucket = client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.upload_from_string(s, content_type = 'text/html')
metadata = {'Cache-control': 'public, max-age=60', 'Content-Type':'text/html'}
#blob.metadata = metadata
#blob.patch()
def upload_html(bucket_name = 'www.paulhtremblay.com'):
files = glob.glob('html_temp/*.html')
for i in files:
head, tail = os.path.split(i)
upload_to_storage(local_path = i, bucket_name = bucket_name,
blob_name = tail)
files2 = glob.glob('html_temp/states/*.html')
for i in files2:
head, tail = os.path.split(i)
upload_to_storage(local_path = i, bucket_name = bucket_name,
blob_name = 'states/{name}'.format(name = tail))
files3 = glob.glob('html_temp/countries/*.html')
for i in files3:
head, tail = os.path.split(i)
upload_to_storage(local_path = i, bucket_name = bucket_name,
blob_name = 'countries/{name}'.format(name = tail))
if __name__ == '__main__':
upload_html()