forked from perliedman/geojson-path-finder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.py
38 lines (26 loc) · 964 Bytes
/
deploy.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
import os
from google.cloud import bigquery
from google.cloud.exceptions import NotFound
from google.cloud import storage
from envsubst import envsubst
PROJECT_ID = os.environ["PROJECT_ID"]
DATASET = os.environ["DATASET"]
LOCATION = os.environ["LOCATION"]
BUCKET_NAME = os.environ["LIBRARY_BUCKET_NAME"]
def deploy_file_to_gcp():
client = storage.Client(project=PROJECT_ID)
bucket = client.bucket(BUCKET_NAME)
blob = bucket.blob('geojson_path_finder.js')
blob.upload_from_filename(filename="dist/geojson_path_finder.js")
def parse_query():
with open('query_template.sql', 'r') as inn:
parsed_query = envsubst(inn.read())
return parsed_query
def deploy():
query = parse_query()
client = bigquery.Client(project=PROJECT_ID, location=LOCATION)
query_job = client.query(query)
results = query_job.result() # Waits for job to complete.
if __name__ == "__main__":
deploy_file_to_gcp()
deploy()