def on_chat(self, msg): r = redis.Redis() # store the data in the database using sqlalchemy chat = Chat(chat_line = msg) DBSession.add(chat) DBSession.commit() # we got a new chat event from the client, send it out to # all the listeners r.publish('chat', dumps(chat.serialize()))
def on_chat(self, msg): r = redis.Redis() # store the data in the database using sqlalchemy chat = Chat(chat_line=msg) DBSession.add(chat) DBSession.commit() # we got a new chat event from the client, send it out to # all the listeners r.publish('chat', dumps(chat.serialize()))
def main(global_config, **settings): config = Configurator() config.include('pyramid_mako') engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) simple_route(config, 'index', '/', index) simple_route(config, 'get_log', '/get_log', get_log, renderer='json') simple_route(config, 'socket_io', 'socket.io/*remaining', socketio_service) config.add_static_view('static', 'static', cache_max_age=3600) app = config.make_wsgi_app() return app
def main(global_config, **settings): config = Configurator() engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) simple_route(config, 'index', '/', index) simple_route(config, 'get_log', '/get_log', get_log, renderer='json') simple_route(config, 'socket_io', 'socket.io/*remaining', socketio_service) config.add_static_view('static', 'static', cache_max_age=3600) app = config.make_wsgi_app() return app
def main(global_config, **settings): config = Configurator() config.include("pyramid_mako") engine = engine_from_config(settings, "sqlalchemy.") DBSession.configure(bind=engine) simple_route(config, "index", "/", index) simple_route(config, "get_log", "/get_log", get_log, renderer="json") simple_route(config, "socket_io", "socket.io/*remaining", socketio_service) config.add_static_view("static", "static", cache_max_age=3600) app = config.make_wsgi_app() return app
def socketio_service(request): r = redis.Redis() socketio = request.environ["socketio"] gevent.spawn(listener, socketio) while True: message = socketio.receive() if message: if message["type"] == "event": if message['name'] == "chat": # store the data in the database using sqlalchemy chat_line = ''.join(message['args']) chat = Chat(chat_line = chat_line) DBSession.add(chat) DBSession.commit() # we got a new chat event from the client, send it out to # all the listeners r.publish('chat', dumps(chat.serialize())) return {}
def get_log(request): return [c.serialize() for c in DBSession.query(Chat).all()]