本文整理汇总了Python中Pubnub.Pubnub.here_now方法的典型用法代码示例。如果您正苦于以下问题:Python Pubnub.here_now方法的具体用法?Python Pubnub.here_now怎么用?Python Pubnub.here_now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pubnub.Pubnub
的用法示例。
在下文中一共展示了Pubnub.here_now方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import here_now [as 别名]
from Pubnub import Pubnub
publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on )
crazy = 'hello_world'
## -----------------------------------------------------------------------
## History Example
## -----------------------------------------------------------------------
def here_now_complete(messages):
print(messages)
pubnub.stop()
pubnub.here_now( {
'channel' : crazy,
'callback' : here_now_complete
})
## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
pubnub.start()
示例2: len
# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import here_now [as 别名]
## http://www.pubnub.com/
import sys
from Pubnub import Pubnub
publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
channel = 'hello_world'
# Synchronous usage
print pubnub.here_now(channel)
# Asynchronous usage
def callback(message):
print(message)
pubnub.here_now(channel, callback=callback, error=callback)
示例3: publish
# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import here_now [as 别名]
'callback' : pres_event
})
def publish():
print("Publishing a test message on '%s' channel..." % channel)
pubnub.publish({
'channel' : channel,
'message' : { 'text':'foo bar' }
})
pres_thread = threading.Thread(target=presence)
pres_thread.daemon=True
pres_thread.start()
sub_thread = threading.Thread(target=subscribe)
sub_thread.daemon=True
sub_thread.start()
time.sleep(3)
publish()
print("waiting for subscribes and presence")
pres_thread.join()
print pubnub.here_now({'channel':channel})
sub_thread.join()
示例4: len
# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import here_now [as 别名]
## -----------------------------------
## PubNub 3.1 Real-time Push Cloud API
## -----------------------------------
import sys
sys.path.append('../')
from twisted.internet import reactor
from Pubnub import Pubnub
publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False
## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key,
secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
crazy = 'hello_world'
def print_cb(message):
print message
pubnub.here_now( {
'channel' : crazy,
'callback' : print_cb
})
示例5: presence
# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import here_now [as 别名]
def presence():
print ("Listening for presence events on '%s' channel..." % channel)
pubnub.presence({"channel": channel, "callback": pres_event})
def publish():
print ("Publishing a test message on '%s' channel..." % channel)
pubnub.publish({"channel": channel, "message": {"text": "foo bar"}})
pres_thread = threading.Thread(target=presence)
pres_thread.daemon = True
pres_thread.start()
sub_thread = threading.Thread(target=subscribe)
sub_thread.daemon = True
sub_thread.start()
time.sleep(3)
publish()
print ("waiting for subscribes and presence")
pres_thread.join()
print pubnub.here_now({"channel": channel})
sub_thread.join()