Created
September 9, 2024 09:15
-
-
Save shibacow/537006edd2a245fac4ee710feabb80a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding:utf-8 -*- | |
from google.cloud import bigquery | |
from google.oauth2 import service_account | |
key_path = 'xxxxxxxxxxxxxxxxxxx.json' | |
credentials = service_account.Credentials.from_service_account_file( | |
key_path, | |
scopes=[ | |
'https://www.googleapis.com/auth/bigquery', | |
'https://www.googleapis.com/auth/cloud-platform', | |
'https://www.googleapis.com/auth/drive.readonly' | |
], | |
) | |
query=''' | |
SELECT count(1) as cnt FROM `dataset.external_table_from_google_sheet` | |
''' | |
client = bigquery.Client( | |
credentials=credentials, | |
project=credentials.project_id, | |
) | |
query_job = client.query(query) | |
rows = query_job.result() | |
for row in rows: | |
print(row.cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment