本文整理汇总了Python中postmonkey.PostMonkey.listInterestGroupings方法的典型用法代码示例。如果您正苦于以下问题:Python PostMonkey.listInterestGroupings方法的具体用法?Python PostMonkey.listInterestGroupings怎么用?Python PostMonkey.listInterestGroupings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类postmonkey.PostMonkey
的用法示例。
在下文中一共展示了PostMonkey.listInterestGroupings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MailchimpLocator
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import listInterestGroupings [as 别名]
class MailchimpLocator(object):
"""Utility for MailChimp API calls.
"""
implements(IMailchimpLocator)
def connect(self):
registry = getUtility(IRegistry)
self.settings = registry.forInterface(IMailchimpSettings)
self.mailchimp = PostMonkey(self.settings.api_key)
def lists(self):
"""Return all available MailChimp lists.
http://apidocs.mailchimp.com/api/rtfm/lists.func.php
"""
#print("MAILCHIMP LOCATOR: lists")
self.connect()
try:
# lists returns a dict with 'total' and 'data'. we just need data
return self.mailchimp.lists()['data']
except MailChimpException:
return []
except PostRequestError:
return []
except:
raise
def default_list_id(self):
self.connect()
if self.settings.default_list:
return self.settings.default_list
lists = self.lists()
if len(lists) > 0:
return lists[0]['id']
def groups(self, list_id=None):
"""Return all available MailChimp interest groups.
@id: the list id to connect to. e.g. u'a1346945ab'. Not the web_id!
http://apidocs.mailchimp.com/api/rtfm/listinterestgroupings.func.php
"""
if not list_id:
return
#print("MAILCHIMP LOCATOR: groups")
self.connect()
try:
# mailchimp returns a list of groups for a single mailinglist.
# We always choose the first and return just the groups part.
return self.mailchimp.listInterestGroupings(id=list_id)[0]
except MailChimpException, error:
if error.code == 211:
# "This list does not have interest groups enabled"
# http://apidocs.mailchimp.com/api/1.3/exceptions.field.php#210-list-_-basic-actions
return
elif error.code == 200:
# "Invalid MailChimp List ID"
# http://apidocs.mailchimp.com/api/1.3/exceptions.field.php#200-list-related-errors
return
raise
示例2: MailchimpLocator
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import listInterestGroupings [as 别名]
class MailchimpLocator(object):
"""Utility for MailChimp API calls.
"""
implements(IMailchimpLocator)
key_account = "collective.mailchimp.cache.account"
key_groups = "collective.mailchimp.cache.groups"
key_lists = "collective.mailchimp.cache.lists"
def __init__(self):
self.mailchimp = None
self.registry = None
self.settings = None
def initialize(self):
if self.registry is None:
self.registry = getUtility(IRegistry)
if self.settings is None:
self.settings = self.registry.forInterface(IMailchimpSettings)
def connect(self):
if self.mailchimp is not None:
return
self.initialize()
self.mailchimp = PostMonkey(self.settings.api_key)
def lists(self):
self.initialize()
cache = self.registry.get(self.key_lists, _marker)
if cache and cache is not _marker:
return cache
return self._lists()
def _lists(self):
self.connect()
try:
# lists returns a dict with 'total' and 'data'. we just need data
return self.mailchimp.lists()['data']
except MailChimpException:
return []
except PostRequestError:
return []
except:
raise
def default_list_id(self):
self.connect()
if self.settings.default_list:
return self.settings.default_list
lists = self.lists()
if len(lists) > 0:
return lists[0]['id']
def groups(self, list_id=None):
if not list_id:
return
self.initialize()
cache = self.registry.get(self.key_groups, _marker)
if cache and cache is not _marker:
groups = cache.get(list_id, _marker)
if groups and groups is not _marker:
return groups
return self._groups(list_id)
def _groups(self, list_id=None):
if not list_id:
return
self.connect()
try:
# mailchimp returns a list of groups for a single mailinglist.
# We always choose the first and return just the groups part.
return self.mailchimp.listInterestGroupings(id=list_id)[0]
except MailChimpException, error:
if error.code == 211:
# "This list does not have interest groups enabled"
# http://apidocs.mailchimp.com/api/1.3/exceptions.field.php#210-list-_-basic-actions
return
elif error.code == 200:
# "Invalid MailChimp List ID"
# http://apidocs.mailchimp.com/api/1.3/exceptions.field.php#200-list-related-errors
return
raise