def save(self, cascade=True, verbose=False, force_sync=False, save_callback=lambda x: x): """ Save the Campaign :param cascade: Also save recursively all attached AdGroups :param force_sync: Force Sync to Apple APIs :param save_callback: Callback function called with the json serialized object as arg :param verbose: Verbosity """ if force_sync or Synchronizable.synchronize( self, save_callback=save_callback): if cascade: for ad_group in self.ad_groups: ad_group.save(verbose=verbose) if self._id: api_put("campaigns/%s" % self._id, data=self.__editable_fields(), org_id=self._org_id, verbose=verbose) else: api_post("campaigns/", data=self.__editable_fields(), org_id=self._org_id, verbose=verbose)
def save(self, verbose=False, force_sync=False, save_callback=lambda x: x): """ Save the AdGroup object :param force_sync: Force Sync to Apple APIs :param save_callback: Callback function called with the json serialized object as arg :param verbose: Verbosity """ if force_sync or Synchronizable.synchronize( self, save_callback=save_callback): keywords_export = [] for keyword in self.keywords: keywords_export.extend( keyword.prepare_for_bulk_export(self._campaign_id, self._id)) api_post("keywords/targeting/", data=keywords_export, verbose=verbose) if self._id: api_put("campaigns/%s/adgroups/%s" % (self._campaign_id, self._id), data=self.__editable_fields(), verbose=verbose) else: api_post("campaigns/%s/adgroups" % (self._campaign_id), data=self.__editable_fields(), verbose=verbose)
def _report(campaign=None, path='', org_id=None, start_time=_today(), end_time=_today(), timezone='UTC', granularity='HOURLY', selector=None, group_by=[], return_records_with_no_metrics=True, return_row_totals=False): if not selector: selector = { "orderBy": [ {"field": "modificationTime", "sortOrder": "DESCENDING"} ], "conditions": [], "pagination": {"offset": 0, "limit": 1000} } data = { 'startTime': start_time, 'endTime': end_time, 'timeZone': timezone, 'granularity': granularity, 'selector': selector, 'groupBy': group_by, 'returnRowTotals': return_row_totals, 'returnRecordsWithNoMetrics': return_records_with_no_metrics } if campaign: url = "reports/campaigns/%s/%s" % (campaign._id, path) else: url = "reports/campaigns" output = [] api_res = api_post(url, org_id=org_id, data=data) try: res = api_res['data']['reportingDataResponse']['row'] except: raise Exception(api_res) # ['data']['error']['errors']) for row in res: base = {} base.update(row['metadata']) if return_row_totals: base.update(row['total']) if campaign: base['adamId'] = campaign._adam_id base['campaignId'] = campaign._id else: base['adamId'] = base['app']['adamId'] base['appName'] = base['app']['appName'] del base['app'] for granularity in row['granularity']: final_row = copy.copy(base) final_row.update(granularity) output.append(convert_keyword_id_to_string(convert_to_float_all_amounts_in_row(final_row))) return pd.DataFrame(output)