You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
632 B
Python
26 lines
632 B
Python
import json
|
|
import os
|
|
|
|
from google.cloud import bigquery
|
|
|
|
client = bigquery.Client()
|
|
|
|
|
|
def push_to_pubsub(request_params):
|
|
errors = client.insert_rows_json(os.environ["BQ_TABLE"], [request_params])
|
|
if errors != []:
|
|
raise Exception("Encountered errors while inserting rows: {}".format(errors))
|
|
|
|
|
|
def main(request):
|
|
request_json = request.get_json(silent=True)
|
|
request_args = request.args
|
|
|
|
if request_json:
|
|
push_to_pubsub(request_json)
|
|
elif request_args:
|
|
push_to_pubsub(request_args)
|
|
else:
|
|
return ("No data provided.", 400)
|
|
return {"status": "ok", "source": "cf_to_bq"}
|