def download_data(): """Initializes the FacebookAdsAPI, retrieves the ad accounts and downloads the data""" logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') FacebookAdsApi.init(config.app_id(), config.app_secret(), config.access_token()) ad_accounts = _get_ad_accounts() download_data_sets(ad_accounts)
def download_data(): """Initializes the FacebookAdsAPI, retrieves the ad accounts and downloads the data""" logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') FacebookAdsApi.init(config.app_id(), config.app_secret(), config.access_token()) ad_accounts = _get_ad_accounts() target_accounts = list(filter(None, config.target_accounts().split(','))) if len(target_accounts) > 0: logging.info('the app can see %s accounts but the configuration specified only %s target accounts: %s', len(ad_accounts), len(target_accounts), ', '.join(target_accounts)) ad_accounts = [ad_account for ad_account in ad_accounts if ad_account['account_id'] in config.target_accounts()] logging.info('after filtering %s accounts will be downloaded: %s', len(target_accounts), ', '.join(target_accounts)) download_data_sets(ad_accounts)
def _job_thread_func(args: ThreadArgs) -> None: job: typing.Optional[JobQueueItem] # Api objects do not seem thread safe at all, create on per thread and nuke the default for # good measure api: FacebookAdsApi = FacebookAdsApi.init(config.app_id(), config.app_secret(), config.access_token()) FacebookAdsApi.set_default_api(None) # No need to lock since this can only change to True, so worst case this does one extra # iteration. Also assignment / reading of booleans should be atomic anyway. while not args.done: job = _get_job_from_queue(args) if job is None: continue _process_job(args, job, api) _log(logging.info, args.logging_mutex, ['thread {0} exited'.format(threading.get_ident())])
def _job_thread_func(args: ThreadArgs) -> None: job: typing.Optional[JobQueueItem] # Api objects do not seem thread safe at all, create on per thread and nuke the default for # good measure api: FacebookAdsApi = FacebookAdsApi.init(config.app_id(), config.app_secret(), config.access_token()) FacebookAdsApi.set_default_api(None) with args.job_list_cv: while not args.job_thread_done: if len(args.job_list) > 0: job = heapq.heappop(args.job_list) args.job_list_cv.release() _process_job(args, job, api) args.job_list_cv.acquire() else: args.job_list_cv.wait() _log(logging.info, args.logging_mutex, ['thread {0} exited'.format(threading.get_ident())])