I modified the default hello_pubsub (Python3.7) function of "Google Cloud functions" service, for connecting to a dataset table which I have created in the "Google Cloud BigQuery" service. But, after many different approaches, I'm clueless on, how to make this function connect to the dataset I created in BigQuery. I am sure there is an error only with SQLite code of the function. Someone, please help me
My code is:
import sqlite3
import base64
def hello_pubsub(event, context):
"""Triggered from a message on a Cloud Pub/Sub topic.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
connection = sqlite3.connect("<BigQueryDataset>")
crsr = connection.cursor()
crsr.execute("SELECT * FROM `iotcoretutorial-xxxxxx.DHT11.DHT11Data` WHERE temperature > 24")
ans= crsr.fetchall()
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
print("Hello "+pubsub_message)
print(ans)
PS: Here iotcoretutorial-xxxxxx refers to the project ID. I used xxxxxx, to hide my project's identity (Please bear with me for that!)
In short iotcoretutorial-xxxxxx.DHT11.DHT11Data is a table created by me on "Google Cloud BigQuery" with temperature and humidity values, which I want to print using hello_pubsub function and do some action if temperature value > 24