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


Python Bus.register方法代码示例

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


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

示例1: Bus

# 需要导入模块: from bus import Bus [as 别名]
# 或者: from bus.Bus import register [as 别名]
# pylint: disable=I0011,C0103
from event import Event
from bus import Bus
from listener import WeatherBot

# 1- Register listeners on the bus
bot_name = 'pyro'
zipcode = 94040
bus = Bus()
bus.register(WeatherBot(bot_name), Event.Types.message_created_event)

# 2- Let's create some events on the bus and see if our listeners pick them up

for i in range(4):
    if i % 2 == 0:
        print "throwing message_created_event"
        bus.notify(Event(Event.Types.message_created_event, {"room_id":1, "data": "{} weather {}".format(bot_name, zipcode), "user_id": 123}))
    else:
        print "throwing user_joins_room"
        bus.notify(Event(Event.Types.user_joins_room, {}))
开发者ID:nija,项目名称:python-bus-poc,代码行数:22,代码来源:main.py

示例2: Bus

# 需要导入模块: from bus import Bus [as 别名]
# 或者: from bus.Bus import register [as 别名]
console_logger.setFormatter(formatter)
# Add console_logger to logger
logger.addHandler(console_logger)
app.logger.addHandler(logger)


# Create an event bus
bus = Bus()

sparklebot_name = 'Pyro'

sparklebot = SparkleBot(name=sparklebot_name, bus=bus)

# Register our new bot with the bus as a listener for
# any Event.Types.message_created_event that are emitted
bus.register(sparklebot, Event.Types.message_created_event)


# ====== END Server Start-up ======



# ====== Routes Definitions ======

######  Flask Routes  ######
# Show homepage
@app.route('/')
def index():
    '''Home page'''

    return render_template("home.html")
开发者ID:phyous,项目名称:hb-chatty,代码行数:33,代码来源:server.py

示例3: Bus

# 需要导入模块: from bus import Bus [as 别名]
# 或者: from bus.Bus import register [as 别名]
# pylint: disable=I0011,C0103
from event import Event
from bus import Bus
from listener import SparkleBot
import os
import re
import urllib
import urllib2
from weather_api import WeatherAPI

# 1- Register listeners on the bus
bot_name = 'Pyro'
zipcode = 94040
bus = Bus()
bus.register(SparkleBot(bot_name, bus=bus, user_id=8), Event.Types.message_created_event)

# 2- Let's create some events on the bus and see if our listeners pick them up
num = 4
for i in range(num):
    if i % num == 0:
        print "throwing message_created_event - weather"
        bus.notify(Event(Event.Types.message_created_event, {"room_id":1, "data": "{} weather {}".format(bot_name, zipcode), "user_id": 2, "user_name": "Anony Mouse"}))
    elif i % num == 1:
        print "throwing message_created_event - help"
        bus.notify(Event(Event.Types.message_created_event, {"room_id":1, "data": "{} help".format(bot_name), "user_id": 2, "user_name": "Anony Mouse"}))
    elif i % num == 2:
        print "throwing message_created_event - story"
        bus.notify(Event(Event.Types.message_created_event, {"room_id":1, "data": "{} story".format(bot_name), "user_id": 2, "user_name": "Anony Mouse"}))
    else:
        print "throwing user_joins_room_event"
        bus.notify(Event(Event.Types.user_joins_room_event, {}))
开发者ID:nija,项目名称:hb-chatty,代码行数:33,代码来源:bot_main.py


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