本文整理汇总了Python中postmonkey.PostMonkey.ping方法的典型用法代码示例。如果您正苦于以下问题:Python PostMonkey.ping方法的具体用法?Python PostMonkey.ping怎么用?Python PostMonkey.ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类postmonkey.PostMonkey
的用法示例。
在下文中一共展示了PostMonkey.ping方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: snapshot_mailchimp
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import ping [as 别名]
def snapshot_mailchimp(verbose=False):
api_key = os.environ.get('MAILCHIMP_API_KEY')
assert api_key, 'No MAILCHIMP_API_KEY defined in environment.'
pm = PostMonkey(api_key, timeout=10)
ping_string = pm.ping()
expected = u'Everything\'s Chimpy!'
assert ping_string==expected, 'Bad handshake, got "%s", expected "%s"' % (ping_string,expected)
if verbose:
print 'handshake ok'
lists = pm.lists()
if not 'data' in lists:
print 'Got bad lists object from server.'
pprint(lists)
raise ValueError('Bad lists object from server')
# Snapshot creation code...
today = datetime.now().date()
for l in lists['data']:
try:
if verbose: print 'Scraping %s...' % l['name']
latest = Session.query(model.SnapshotOfMailchimp)\
.filter(model.SnapshotOfMailchimp.name==l['name'])\
.order_by(model.SnapshotOfMailchimp.timestamp.desc())\
.first()
if latest and latest.timestamp>=today:
if verbose: print ' -> most recent snapshots have already been processed.'
continue
snapshot = model.SnapshotOfMailchimp(\
name = l['name'],\
members = l['stats']['member_count'],
timestamp = today)
if verbose: print ' -> ',snapshot.toJson()
Session.add(snapshot)
Session.commit()
except Exception, e:
pprint({'list':l,'exception':str(e)})
示例2: test_mailchimp_ping_method
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import ping [as 别名]
def test_mailchimp_ping_method(mock_class):
mock_class().ping = MagicMock(
return_value=u"Everything's Chimpy!"
)
from postmonkey import PostMonkey
pm = PostMonkey('123')
assert pm.ping() == u"Everything's Chimpy!"
示例3: valid_api_key
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import ping [as 别名]
def valid_api_key(data):
if len(data.api_key) == 0:
return
mailchimp = PostMonkey(data.api_key)
try:
return mailchimp.ping()
except:
raise Invalid(
u"Your MailChimp API key is not valid. Please go " +
u"to mailchimp.com and check your API key.")
示例4: valid_api_key
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import ping [as 别名]
def valid_api_key(obj):
registry = getUtility(IRegistry)
mailchimp_settings = registry.forInterface(IMailchimpSettings)
if len(mailchimp_settings.api_key) == 0:
return
mailchimp = PostMonkey(mailchimp_settings.api_key)
try:
return mailchimp.ping()
except:
raise Invalid(u"Your MailChimp API key is not valid. Please go " +
"to mailchimp.com and check your API key.")
示例5: Mocker
# 需要导入模块: from postmonkey import PostMonkey [as 别名]
# 或者: from postmonkey.PostMonkey import ping [as 别名]
from mocker import Mocker
from mocker import ANY
mocker = Mocker()
postmonkey = mocker.replace("postmonkey")
pm = postmonkey.PostMonkey(ANY)
pm.ping()
mocker.result(u"Everything's Chimpy!")
mocker.replay()
from postmonkey import PostMonkey
mailchimp = PostMonkey('123')
print(mailchimp.ping())