Skip to content

Instantly share code, notes, and snippets.

@vijayanandrp
Created January 24, 2018 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijayanandrp/b2edb20dbbfde2cdad62836cfc096fd7 to your computer and use it in GitHub Desktop.
Save vijayanandrp/b2edb20dbbfde2cdad62836cfc096fd7 to your computer and use it in GitHub Desktop.
from google.cloud import bigquery
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'Google Analytics POC.json'
client = bigquery.Client()
query_job = client.query("""
SELECT
CONCAT(
'https://stackoverflow.com/questions/',
CAST(id as STRING)) as url,
view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE tags like '%google-bigquery%'
ORDER BY view_count DESC
LIMIT 10""")
results = query_job.result() # Waits for job to complete.
for row in results:
print("{} : {} views".format(row.url, row.view_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment