當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。