gcp
This commit is contained in:
28
libs/gcp/gcp_bigquery.py
Normal file
28
libs/gcp/gcp_bigquery.py
Normal file
@@ -0,0 +1,28 @@
|
||||
'''
|
||||
GCP BigQuery functions for WeirdAAL
|
||||
'''
|
||||
|
||||
import google.auth
|
||||
import googleapiclient.discovery
|
||||
import os
|
||||
import sys
|
||||
|
||||
from google.oauth2 import service_account
|
||||
|
||||
from googleapiclient.errors import HttpError
|
||||
|
||||
from google.cloud import bigquery, exceptions
|
||||
from google.cloud.exceptions import *
|
||||
|
||||
|
||||
def gcp_bigquery_list_datasets(project_id, credentials):
|
||||
bigquery_client = bigquery.Client(project=credentials.project_id)
|
||||
datasets = list(bigquery_client.list_datasets())
|
||||
project = bigquery_client.project
|
||||
|
||||
if datasets:
|
||||
print('Datasets in project {}:'.format(project))
|
||||
for dataset in datasets: # API request(s)
|
||||
print('\t{}'.format(dataset.dataset_id))
|
||||
else:
|
||||
print('{} project does not contain any datasets.'.format(project))
|
||||
@@ -35,5 +35,5 @@ def gcp_storage_list_blobs(credentials, bucket_name):
|
||||
blobs = bucket.list_blobs()
|
||||
|
||||
for blob in blobs:
|
||||
print(blob.name)
|
||||
print('\t{}'.format(blob.name))
|
||||
print('\n')
|
||||
Reference in New Issue
Block a user