当前位置: 首页>>代码示例>>Python>>正文


Python FacebookAdsApi.new_batch方法代码示例

本文整理汇总了Python中facebook_business.api.FacebookAdsApi.new_batch方法的典型用法代码示例。如果您正苦于以下问题:Python FacebookAdsApi.new_batch方法的具体用法?Python FacebookAdsApi.new_batch怎么用?Python FacebookAdsApi.new_batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在facebook_business.api.FacebookAdsApi的用法示例。


在下文中一共展示了FacebookAdsApi.new_batch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import new_batch [as 别名]
class API:

    api = None
    object_queue = None

    batch = None

    class request_bundle:
        element = None
        success_callback = None
        failure_callback = None
        mode = None
        def __init__(self, target, m, success = None, failure = None):
            self.element = target
            self.mode = m
            self.success_callback = success
            self.failure_callback = failure

    def __init__(self, clientid, appsecret, token):
        session = FacebookSession(
                clientid,
                appsecret,
                token
        )
        self.api = FacebookAdsApi(session)
        self.object_queue = queue.Queue()
        self.batch = self.api.new_batch()

    class RemoteMode:
        CREATE = 0
        UPDATE = 1
        DELETE = 2
        
    def remote_create(self, target, success_event = None, failure_event = None):
        obj = API.request_bundle(target, API.RemoteMode.CREATE, success_event, failure_event)
        self.object_queue.put(obj)

    def remote_update(self, target, success_event = None, failure_event = None):
        obj = API.request_bundle(target, API.RemoteMode.UPDATE, success_event, failure_event)
        self.object_queue.put(obj)

    def remote_delete(self, target, success_event = None, failure_event = None):
        obj = API.request_bundle(target, API.RemoteMode.DELETE, success_event, failure_event)
        self.object_queue.put(obj)

    def execute(self):
        #time.sleep(300)
        totalcount = self.object_queue.qsize()
        currentcount = 0
        finished = False

        while not finished:
            for i in range(0, 30):
                if self.object_queue.qsize() == 0:
                    break;
                
                obj = self.object_queue.get()
                item = obj.element
                mode = obj.mode
                success_event = obj.success_callback
                fail_event = obj.failure_callback

                if mode == API.RemoteMode.CREATE:
                    item.remote_create(batch = self.batch, success=success_event ,failure= fail_event)
                elif mode == API.RemoteMode.UPDATE:
                    item.remote_update(batch = self.batch, success=success_event, failure = fail_event)
                elif mode == API.RemoteMode.DELETE:
                    item.remote_delete(batch = self.batch, success = success_event, failure = fail_event)
                currentcount = currentcount+1

            print 'Processing... : '+str(currentcount)+'/'+str(totalcount)
            self.batch.execute()
            self.batch = self.api.new_batch()
            if self.object_queue.qsize() == 0:
                print 'Finish work'
                finished = True
            else:
                print 'Wait 5min for next work'
                time.sleep(600)
开发者ID:flashwade03,项目名称:facebook-businessapi-controller,代码行数:81,代码来源:fb_api.py


注:本文中的facebook_business.api.FacebookAdsApi.new_batch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。