def get_account_business_info(self, account_id):
     account = AdAccount('act_%s' % str(account_id))
     account.remote_read(fields=[AdAccount.Field.business])
     business_info = account[AdAccount.Field.business]
     if business_info:
         return business_info
     return {}
예제 #2
0
def test_campaign_upload(campaign_data, account):
    """
    Args:
        campaign_data (dict): parameters parsed from Json
        account (str): Account where to upload the campaing

    Returns:
        TYPE: Description
    """
    # Check if we're working with the correct account
    active_account = AdAccount(account)
    active_account.remote_read(fields=[AdAccount.Field.name])

    print('Uploading a campaign to %s' % active_account[AdAccount.Field.name])

    confirm = input('Do you want to continue? Y/N  --> ')
    if confirm not in ('y', 'Y'):
        print('Aborted campaign upload')
        return

    print("\nRunning validations...")
    # Initial validations
    validate(campaign_data)

    print("\nUploading campaign...")
    # Get existing or create a new campaign
    campaign_id = create_campaign(campaign_data, account)
    print('Campaign uploaded!')
    # Create Ad set
    print("\nUploading AdSet...")
    create_ad_set(campaign_data, account, campaign_id)
    print('Ad set uploaded!')
 def get_account_info(self, account_id):
     account = AdAccount('act_%s' % str(account_id))
     account.remote_read(fields=[
         AdAccount.Field.id, AdAccount.Field.name,
         AdAccount.Field.account_status
     ])
     if account: return account
     return {}
예제 #4
0
파일: main.py 프로젝트: Peridian/etl
def facebook_data_extraction(config):
    '''
    Facebook Ads platform data extraction
    '''
    facebook_get_service(config)
    me = User(fbid='me')
    print('me', me)
    print('me.remote_read(fields=[User.Field.permissions])', me.remote_read())
    ad_account = AdAccount(config['ad_account_id'])
    print('ad_account', ad_account.remote_read())
    print('ad_account', ad_account.get_campaigns())
    return ''
    def generate_rows(self,
                      dataset_schema=None,
                      dataset_partitioning=None,
                      partition_id=None,
                      records_limit=-1):
        """
        The main reading method.

        Returns a generator over the rows of the dataset (or partition)
        Each yielded row must be a dictionary, indexed by column name.

        The dataset schema and partitioning are given for information purpose.
        """
        FacebookAdsApi.init(access_token=self.access_token, api_version='v3.3')

        params = {
            'time_range': {
                'since': self.date_start,
                'until': self.date_stop
            },
            'breakdowns': self.breakdowns,
            'level': self.level,
            'time_increment': 1
        }

        async_job = AdAccount(self.ad_account_id).get_insights_async(
            fields=self.fields, params=params)

        while not async_job.remote_read().get(
                "async_status") == 'Job Completed':
            time.sleep(1)

        resulting_adaccount_lines = async_job.get_result()

        for line in resulting_adaccount_lines:
            yield line.export_data()