本文整理汇总了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)