Example #1
0
  def execute(self, context):
    if self.sa360_hook is None:
      self.sa360_hook = GoogleSearchAds360Hook(
          gcp_conn_id=self.gcp_conn_id,
          delegate_to=self.delegate_to)
    if self.gcs_hook is None:
      self.gcs_hook = GoogleCloudStorageHook(
          google_cloud_storage_conn_id=self.gcp_conn_id,
          delegate_to=self.delegate_to)

    request = self.sa360_hook.get_service().reports().get(
        reportId=self.report_id)
    response = request.execute()

    temp_file = tempfile.NamedTemporaryFile(delete=False)
    try:
      self._download_report(self.report_id, temp_file, len(response['files']))
      destination_object_name = self._get_destination_uri(
          self.destination_object, temp_file)
      self.gcs_hook.upload(
          bucket=self.destination_bucket,
          object=destination_object_name,
          filename=temp_file.name,
          multipart=True)
      context['task_instance'].xcom_push(
          'destination_bucket', self.destination_bucket)
      context['task_instance'].xcom_push(
          'destination_object', destination_object_name)
    finally:
      temp_file.close()
      os.unlink(temp_file.name)
Example #2
0
    def execute(self, context):
        if self.hook is None:
            self.hook = GoogleSearchAds360Hook(gcp_conn_id=self.gcp_conn_id,
                                               delegate_to=self.delegate_to)

        report_body = json.loads(self.report)
        request = self.hook.get_service().reports().request(body=report_body)
        response = request.execute()

        context['task_instance'].xcom_push('report_id', response['id'])
Example #3
0
  def poke(self, context):
    if self.hook is None:
      self.hook = GoogleSearchAds360Hook(
          gcp_conn_id=self.gcp_conn_id,
          delegate_to=self.delegate_to)

    request = self.hook.get_service().reports().get(reportId=self.report_id)
    response = request.execute()

    if response:
      return response.get('isReportReady', False)

    return False
Example #4
0
  def execute(self, context):
    file = Path(self.conversions_file)
    if not file.is_file():
      raise AirflowException(
        f'conversions_file {self.conversions_file} not found'
      )

    if self.hook is None:
      self.hook = GoogleSearchAds360Hook(
        gcp_conn_id=self.gcp_conn_id, delegate_to=self.delegate_to
      )

    conversions = json.loads(file.read_text())
    if not conversions:
      self.log.info('No conversions to insert')
      return

    request = (
      self.hook.get_service()
      .conversion()
      .insert(body={'conversion': conversions})
    )
    request.execute()