You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/10/02 12:27:12 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #6228: [AIRFLOW-5379] Add Google Search Ads 360 operators

mik-laj commented on a change in pull request #6228: [AIRFLOW-5379] Add Google Search Ads 360 operators
URL: https://github.com/apache/airflow/pull/6228#discussion_r330519372
 
 

 ##########
 File path: airflow/gcp/example_dags/example_search_ads.py
 ##########
 @@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+Example Airflow DAG that shows how to use SearchAds.
+"""
+import os
+
+from airflow.utils import dates
+from airflow import models
+from airflow.gcp.operators.search_ads import (
+    GoogleSearchAdsInsertReportOperator,
+    GoogleSearchAdsDownloadReportOperator,
+)
+from airflow.gcp.sensors.search_ads import GoogleSearchAdsReportSensor
+
+# [START howto_search_ads_env_variables]
+AGENCY_ID = os.environ.get("GMP_AGENCY_ID")
+ADVERTISER_ID = os.environ.get("GMP_ADVERTISER_ID")
+GCS_BUCKET = os.environ.get("GMP_GCS_BUCKET", "test-cm-bucket")
+
+REPORT = {
+    "reportScope": {"agencyId": AGENCY_ID, "advertiserId": ADVERTISER_ID},
+    "reportType": "account",
+    "columns": [{"columnName": "agency"}, {"columnName": "lastModifiedTimestamp"}],
+    "includeRemovedEntities": False,
+    "statisticsCurrency": "usd",
+    "maxRowsPerFile": 1000000,
+    "downloadFormat": "csv",
+}
+# [END howto_search_ads_env_variables]
+
+default_args = {"start_date": dates.days_ago(1)}
+
+with models.DAG(
+    "example_search_ads",
+    default_args=default_args,
+    schedule_interval=None,  # Override to match your needs
+) as dag:
+    # [START howto_search_ads_generate_report_operator]
+    generate_report = GoogleSearchAdsInsertReportOperator(
+        report=REPORT, task_id="generate_report"
+    )
+    report_id = "{{ task_instance.xcom_pull('generate_report', key='report_id') }}"
+    # [END howto_search_ads_generate_report_operator]
+
+    # [START howto_search_ads_get_report_operator]
+    wait_for_report = GoogleSearchAdsReportSensor(
+        report_id=report_id, task_id="wait_for_report"
 
 Review comment:
   ```suggestion
           report_id="{{ task_instance.xcom_pull('generate_report', key='report_id') }}", task_id="wait_for_report"
   ```
   I think it's worth including in one snippet of code - `[START/END]`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services