Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

gcp functions save BQ

from google.cloud import bigquery<br />from google.cloud import storage<p>def export_to_gcs():<br /># BQ Query to get add to cart sessions<br />QUERY = "SELECT<br />CONCAT(fullVisitorId,'.', CAST(visitId AS string)) AS sessionId,<br />hit.page.pageTitle AS pageTitle,<br />CONCAT(hit.page.hostname, hit.page.pagePath) AS pageURL,<br />hit.page.hostname AS hostname,<br />product.productSKU AS productSKU,<br />product.v2ProductName AS productName,<br />product.v2ProductCategory AS productCategory,<br />product.productPrice/1000000 AS productPrice,<br />product.productQuantity AS productQuantity<br />FROM<br />`..ga_sessions_*`,<br />UNNEST(hits) AS hit,<br />UNNEST(hit.product) AS product<br />WHERE<br />hit.eCommerceAction.action_type = '3'<br />AND _TABLE_SUFFIX = FORMAT_DATETIME('%Y%m%d',DATETIME_ADD(CURRENT_DATETIME(),INTERVAL -1 DAY))"<br />bq_client = bigquery.Client()<br />query_job = bq_client.query(QUERY) # API request<br />rows_df = query_job.result().to_dataframe() # Waits for query to finish<br />storage_client = storage.Client()<br />bucket = storage_client.get_bucket('BucketName')<br />blob = bucket.blob('Add_to_Cart.csv')<br />blob.upload_from_string(rows_df.to_csv(sep=';',index=False,<br />encoding='utf-8'),content_type='application/octet-stream')<br />
Comment

PREVIOUS NEXT
Code Example
Python :: bolumden kalan python 
Python :: how to navigate to a sub html script selenium python 
Python :: command to upgrade the pip 
Shell :: linux get cpu frequency 
Shell :: remove phpmyadmin from ubuntu 
Shell :: uninstall angular cli 
Shell :: amazon linux 2 install stress 
Shell :: how to install obs on ubuntu 
Shell :: install sklearn 
Shell :: Unit mongodb.service could not be found ubuntu 
Shell :: [ERROR] Error while getting Capacitor CLI version. Is Capacitor installed? 
Shell :: ubuntu install telegram 
Shell :: git set email for project 
Shell :: mvn clean install skip tests 
Shell :: update angular cli globally 
Shell :: how to update git submodule 
Shell :: error: failed to synchronize all databases (invalid or corrupted database (PGP signature)) 
Shell :: how to fix /opt/lampp/bin/mysql.server: 264: kill: no such process 
Shell :: uninstall npm ubuntu 
Shell :: uninstall imagemagick ubuntu 
Shell :: uninstall postgres brew 
Shell :: how to get list port linux cmd 
Shell :: ubuntu uninstall thingsboard 
Shell :: flush dns cache linux 
Shell :: snap install atom 
Shell :: how to clear container in docker 
Shell :: count number of files linux command 
Shell :: uninstall nginx 
Shell :: zoom download linux 
Shell :: ls show octal permissions 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =