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


Python Pubnub.publish方法代码示例

本文整理汇总了Python中Pubnub.Pubnub.publish方法的典型用法代码示例。如果您正苦于以下问题:Python Pubnub.publish方法的具体用法?Python Pubnub.publish怎么用?Python Pubnub.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pubnub.Pubnub的用法示例。


在下文中一共展示了Pubnub.publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RemotePubNub

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
class RemotePubNub():

    def __init__(self, PUBNUB_PUBLISH_KEY="demo", PUBNUB_SUBSCRIBE_KEY="demo", queue=None):
        self.pubnub = Pubnub(publish_key=PUBNUB_PUBLISH_KEY, subscribe_key=PUBNUB_SUBSCRIBE_KEY)
        self.queue = queue

    def get_queue(self):
        return self.queue

    def publish(self, channel, message):
        self.pubnub.publish(channel, message)
        #logging.info("message published")

    def subscribe(self, channel):
        self.pubnub.subscribe(
            channel, callback=self.parse_command, error=self.sub_error,
            connect=self.sub_connect, disconnect=self.sub_disconnect)

    def parse_command(self, message, channel):
        if self.queue is not None:
            print message
            self.queue.put(message)

    def sub_error(message):
        logging.ERROR(message)

    def sub_connect(self, channel):
        message = 'Connected to: %s' % channel
        logging.info(message)

    def sub_disconnect(self, message):
        logging.info(message)
开发者ID:mjsrs,项目名称:cubieboard-scheduler,代码行数:34,代码来源:remote.py

示例2: post_save

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
 def post_save(cls, sender, document, **kwargs):
     cfg = current_app.config
     pubnub = Pubnub(
         publish_key=cfg["PUBNUB_PUB_KEY"],
         subscribe_key=cfg["PUBNUB_SUB_KEY"],
         ssl_on=False,
         )
     pubnub.publish(channel="globaldisaster",
                    message=json.dumps(document.asdict()))
开发者ID:gudeg-united,项目名称:mishapp-api,代码行数:11,代码来源:database.py

示例3: startStockPicker

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
def startStockPicker(server,port):

	global globalQueueRef

	#Step 1 - Initialize MongoDB & PubNub Connection
	mongoconn = pymongo.MongoClient(server,port)
	db        = mongoconn.stockdb
	coll      = db.stockcollection 

	#Setup index on time to fetch the latest update
	coll.create_index([('time',DESCENDING)])

	#YOUR PUBNUB KEYS - Replace the publish_key and subscriber_key below with your own keys
	pubnub = Pubnub(publish_key="<your publish key>",subscribe_key="<your subscribe key>")

	#Step 2 - Check and define the metadata ( index names )
	metaDataInit(coll)

	#Step 3 - Set the parameters , max periodicity , random range
	updateTime = 10 #Max ten seconds for every price update
	numOfItems = 4  #Four indices to manage

	random.seed()

	#Step 4 - Setup the Queue and ClientListener Thread
	clientQueue = Queue()
	clientListener = ClientListenerThread(server,port,clientQueue,pubnub)
	clientListener.start()

	globalQueueRef = clientQueue

	#Step 5 - Setup PubNub Subscription for client requests
	pubnub.subscribe("stockhistory", historyCallback,historyError)

	#Step 6 - Start the stock picking loop
	while True:

		#Step 6.1 - Wait for random time
		time.sleep(random.randint(1,updateTime))
		
		#Step 6.2 - Wake up and update the stock price for one of the index
		newPriceData = getUpdatedPrice(coll)

		#Step 6.3 - Update the new price in DB
		print "New Price Update " + str(newPriceData)
		coll.insert(newPriceData)

		#Step 6.4 - Publish over Pubnub , stockdata channel
		broadcastData = { 'name'   : newPriceData['name'],
						  'value'  : newPriceData['value'],
						  'change' : newPriceData['change'],
						  'time' : newPriceData['time'],

						}

		pubnub.publish('stockdata',json.dumps(broadcastData))
开发者ID:shyampurk,项目名称:mongodb-pubnub,代码行数:58,代码来源:stockticker.py

示例4: pubnubmessager

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
class pubnubmessager(Observer):
    def __init__(self):
      self.pn = Pubnub(config.pubnub_pubkey, config.pubnub_subkey)
      print("Started")

    def opportunity(self, profit, volume, buyprice, kask, sellprice, kbid, perc,
                    weighted_buyprice, weighted_sellprice):
        if profit > config.profit_thresh and perc > config.perc_thresh:
            message = "profit: %f USD with volume: %f BTC - buy at %.4f (%s) sell at %.4f (%s) ~%.2f%%" % (profit, volume, buyprice, kask, sellprice, kbid, perc)
            self.pn.publish({'channel' : config.pubnub_topic, 'message' :{ 'msg' : message}})
开发者ID:sscarduzio,项目名称:bitcoin-arbitrage,代码行数:12,代码来源:pubnubmessager.py

示例5: startStockPicker

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
def startStockPicker(server,port):

	global globalQueueRef
	global graph

	#Step 1 - Initialize MongoDB & PubNub Connection
	# py2neo.set_auth_token('%s:%s' % (NEO_HOST, NEO_PORT), NEO_AUTH_TOKEN)
	graph = Graph('%s://%s:%[email protected]%s:%s/db/data/' % 
	(NEO_PROTOCOL, NEO_USER, NEO_PASSWORD, NEO_HOST, NEO_PORT))

	#YOUR PUBNUB KEYS - Replace the publish_key and subscriber_key below with your own keys
	pubnub = Pubnub(publish_key="<your pub key>",subscribe_key="<your sub key>")

	#Step 2 - Check and define the metadata ( index names )
	metaDataInit()

	#Step 3 - Set the parameters , max periodicity , random range
	updateTime = 10 #Max ten seconds for every price update
	numOfItems = 4  #Four indices to manage

	random.seed()

	#Step 4 - Setup the Queue and ClientListener Thread
	clientQueue = Queue()
	clientListener = ClientListenerThread(server,port,clientQueue,pubnub)
	clientListener.start()

	globalQueueRef = clientQueue

	#Step 5 - Setup PubNub Subscription for client requests
	pubnub.subscribe("stockhistory", historyCallback,historyError)

	#Step 6 - Start the stock picking loop
	while True:

		#Step 6.1 - Wait for random time
		time.sleep(random.randint(1,updateTime))
		
		#Step 6.2 - Wake up and update the stock price for one of the index
		newPriceData = getUpdatedPrice()

		#Step 6.3 - Update the new price in DB
		print "New Price Update " + str(newPriceData)

		#Step 6.4 - Publish over Pubnub , stockdata channel
		broadcastData = { 'name'   : newPriceData['name'],
						  'value'  : newPriceData['value'],
						  'change' : newPriceData['change'],
						  'time' : newPriceData['time'],

						}

		pubnub.publish('stockdata',json.dumps(broadcastData))
开发者ID:davidfauth,项目名称:neo4j-pubnub,代码行数:55,代码来源:stocktickerneo.py

示例6: pinterest

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
class pinterest(object):
    def __init__(self, publish_key,
                 subscribe_key):
        
        self.publish_key = publish_key
        self.subscribe_key = subscribe_key
        self.pubnub = Pubnub( 'pub-c-6f928209-b8a8-4131-9749-7470ead38747', 'sub-c-6d212f32-404e-11e4-a498-02ee2ddab7fe', None, False)
    
    
    
    def send(self, channel, message):
        # Sending message on the channel
        self.pubnub.publish({
                            'channel' : channel,
                            'message' : message})
开发者ID:banasrini,项目名称:pinterest-pubnub,代码行数:17,代码来源:pinterest-pubnub.py

示例7: push

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
 def push(cls, channel, message_dict):
     pubnub = Pubnub(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY, False )
     info = pubnub.publish({
         'channel' : channel,
         'message' : json.dumps(message_dict)
     })
     return info
开发者ID:rgan,项目名称:media_upload,代码行数:9,代码来源:push_service.py

示例8: iotbridge

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
class iotbridge(object):
    def __init__(self, publish_key, subscribe_key, uuid):

        self.publish_key = publish_key
        self.subscribe_key = subscribe_key
        self.uuid = uuid
        self.pubnub = Pubnub("demo", "demo", None, False)
        self.pubnub.uuid = self.uuid

    def send(self, channel, message):
        # Sending message on the channel
        self.pubnub.publish(channel, message)

    def connect(self, channel, callback):
        # Listening for messages on the channel
        self.pubnub.subscribe(channel, callback=callback)
开发者ID:rkreddybogati,项目名称:PiToPubNub,代码行数:18,代码来源:iotconnector.py

示例9: Streamteam

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
class Streamteam(object):

    def __init__(self, args):
        self.channel = args.channel
        self.pubnub = Pubnub(
            args.publish,
            args.subscribe,
            None,
            False
        )

    def publish(self, m):
        def callback(message):
            return message

        self.pubnub.publish(
            self.channel,
            m,
            callback=callback,
            error=callback
        )

    def subscribe(self):

        def callback(message, channel):
                print(message)

        def error(message):
            print("ERROR : " + str(message))

        def connect(message):
            print("CONNECTED")

        def reconnect(message):
            print("RECONNECTED")

        def disconnect(message):
            print("DISCONNECTED")

        self.pubnub.subscribe(
            self.channel,
            callback=callback,
            error=callback,
            connect=connect,
            reconnect=reconnect,
            disconnect=disconnect
        )
开发者ID:svlsummerjam,项目名称:pubnub-time-stream,代码行数:49,代码来源:pubnub-time-stream.py

示例10: push_cbk

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
def push_cbk(sender, **kwargs):
    istance = kwargs.get('instance')
    if istance:
        print "Account balance: %s" % istance.balance 
        pubnub = Pubnub(publish_key='pub-ed4e8fc6-b324-426c-8697-ec763129b026',
                            subscribe_key='sub-31c9765c-c453-11e1-b76c-1b01c696dab3',
                            ssl_on=True)
        info = pubnub.publish({'channel' : istance.notif_channel,
                                'message' : 'Current balance ' + unicode(istance.balance)  })
        print info
开发者ID:Macodom,项目名称:django-pubnub,代码行数:12,代码来源:views.py

示例11: Streamteam

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
class Streamteam(object):

    def __init__(self, args):
        self.channel = args.channel
        self.pubnub = Pubnub(
                args.publish,
                args.subscribe,
                None,
                False
        )
        
    def publish(self, message):
        self.pubnub.publish({
            'channel'  : self.channel,
            'message' : message
        })
    
    def subscribe(self):
        def receive(message):
           # q = ""
            s = ""
            v = ""
            names = "gyroX gyroY AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4".split(" ")
            os.system('clear')
            for i in names:
               # q += str(message['quality'][i]) + " "
                v += str(message['values'][i]) + "   "

                while len(i) < 7:
                    i += " "
                s += i
            print("Channel : " + s)
           # print("Quality : " + q)
            print("Values  : " + v)
            return True
        
        self.pubnub.subscribe({
            'channel' : self.channel,
            'callback' : receive
        })
开发者ID:jamesbeedy,项目名称:emotiv-stream-team,代码行数:42,代码来源:streamteam.py

示例12: send

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
def send(channel, message, **kwargs):
    """
    Site: http://www.pubnub.com/
    API: https://www.mashape.com/pubnub/pubnub-network
    Desc: real-time browser notifications

    Installation and usage:
    pip install -U pubnub
    Tests for browser notification http://127.0.0.1:8000/browser_notification/
    """

    pubnub = Pubnub(
        publish_key=settings.PUBNUB_PUB_KEY,
        subscribe_key=settings.PUBNUB_SUB_KEY,
        secret_key=settings.PUBNUB_SEC_KEY,
        ssl_on=kwargs.pop('ssl_on', False), **kwargs)
    return pubnub.publish(channel=channel, message={"text": message})
开发者ID:GisHel,项目名称:django-db-mailer,代码行数:19,代码来源:push.py

示例13: print

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
    print('User file created...')
    return userFile

publish_key   = 'pub-c-ea55afd0-74eb-4ed4-9f56-4cd96bb87b0a'
subscribe_key = 'sub-c-55cf6ccc-4585-11e4-8772-02ee2ddab7fe'
secret_key    = 'demo'
cipher_key    =  ''
ssl_on        = False

pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)

userFile = open('userFile')
userData = userFile.read()

name = userData.split(',')[0]
rHR = userData.split(',')[1]
phNum = userData.split(',')[2]
usrNum = userData.split(',')[3]

usrJson = userFileGen(name,rHR,phNum,usrNum)

pubnub.publish('usrid_channel', usrJson)

os.system('./googlet2s.sh User Name ' + name )
os.system('./googlet2s.sh resting heart rate ' + rHR)

print('User File Uploaded...')


开发者ID:AnthroTek-Engineering,项目名称:BioJAK,代码行数:30,代码来源:userIdGen.py

示例14: len

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
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 'demo'
ssl_on        = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiat Class
## -----------------------------------------------------------------------
pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on )
crazy  = 'hello_world'

## -----------------------------------------------------------------------
## Publish Example
## -----------------------------------------------------------------------
def publish_complete(info):
    print(info)

pubnub.publish({
    'channel' : crazy,
    'message' : {
            'some_text' : 'Hello World!'
        },
    'callback' : publish_complete
})

## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
reactor.run()
开发者ID:Vall3y,项目名称:pubnub-api,代码行数:32,代码来源:publish-example.py

示例15: connect_cb

# 需要导入模块: from Pubnub import Pubnub [as 别名]
# 或者: from Pubnub.Pubnub import publish [as 别名]
def connect_cb():
    print 'Connect'

def subscribe_result(response):
    print response

pubnub.subscribe({
    'channel' : crazy,
    'callback' : subscribe_result,
    'connect' : connect_cb 
})
## -----------------------------------------------------------------------
## Publish Example
## -----------------------------------------------------------------------
'''
def publish_complete(info):
    print(info)

## Publish string
pubnub.publish({
    'channel' : crazy,
    'message' : 'Hello World!',
    'callback' : publish_complete
})

## Publish list
li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
pubnub.publish({
    'channel' : crazy,
    'message' : li,
开发者ID:Mike-Forrester,项目名称:python,代码行数:32,代码来源:subscribe-example.py


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