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


Python PostMonkey.ping方法代码示例

本文整理汇总了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)})
开发者ID:e6,项目名称:activityapi,代码行数:37,代码来源:snapshot_mailchimp.py

示例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!"
开发者ID:tisto,项目名称:mock-testing-in-python,代码行数:10,代码来源:example-mock.py

示例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.")
开发者ID:kingel,项目名称:collective.mailchimp,代码行数:12,代码来源:interfaces.py

示例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.")
开发者ID:fourdigits,项目名称:collective.mailchimp,代码行数:13,代码来源:interfaces.py

示例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())
开发者ID:tisto,项目名称:mock-testing-in-python,代码行数:17,代码来源:example-mocker.py


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