Exemplo n.º 1
0
  def  worker (self):

       print "simulador worker"
       while 1:
         msgFromController = self.ser.readline().strip()
         if (msgFromController=="#estadoPlanta!"):
           self.planta.ref = xref 
           # y, ref
           # Tests
           #(a,b) = genRandomPairs()
           # envia (y , ref)
           self.iteration += 1 
           myTime = time.time()
        
           estado = {'outs':[self.planta.out, self.planta.ref - self.planta.out, self.planta.actu], 'ts':myTime, 'msg_id':self.iteration}
           redis.publish (toRedisOut, json.dumps(estado))
           print "estado planta: ", estado
        
           msg = self.armaMsg(floatToDigital(self.planta.out), floatToDigital(self.planta.ref))
           self.sendMessageToController (msg)

         else: 
           try:
             actu = msgFromController.strip('#').strip('!')
             self.planta.iterate( digitalToFloat(int(actu)))
           except:
             pass
Exemplo n.º 2
0
def broadcast(msg: pyais.messages.NMEAMessage):
    is_fragmented = msg.count > 1
    # if is_fragmented:
    #     print("Fragmented packet:", msg)
    # else:
    #     print("Single packet:", msg)

    ais_message = AisType()
    ais_message.entryPoint = "airwaves_ais_client"
    ais_message.ourName = config.PYAW_HOSTNAME
    ais_message.srcName = config.AIS_SOURCE["name"]
    ais_message.srcLat = config.AIS_SOURCE["lat"]
    ais_message.srcLon = config.AIS_SOURCE["lon"]
    ais_message.srcPosMode = config.AIS_SOURCE["posMode"]
    ais_message.dataOrigin = "rtl-ais"
    ais_message.raw = msg.raw.decode("utf-8")
    ais_message.payload = msg.data.decode("utf-8")

    ais_parsed = msg.decode()

    if is_fragmented:
        ais_message.isAssembled = True

    # Populate the structure from parsed VDM
    ais_message.populateFromParsedVdm(ais_parsed)

    # Valid message and emit if lat/lon are present
    # if ais_message.lat and ais_message.lon:
    # print(ais_message.to_dict())
    redis.publish("room:vehicles", json.dumps(ais_message.to_dict()))
def main():
    """
    main entry point for the program
    The return value will be the returncode for the program
    """
    _initialize_stderr_logging()
    log = logging.getLogger("main")
    log.info("program starts")

    args = _parse_commandline()
    redis = _create_redis_connection()

    start_time = time.time()
    elapsed_time = 0.0
    while elapsed_time < args.test_duration:
        try:
            key, count = _store_one_key(args)
        except Exception:
            log.exception("_store_one_key")
            return 1

        # there is some latency in file_name_set_manager
        # so we pause before notifying the consumer
        interval = random.uniform(args.min_key_interval, args.max_key_interval)
        time.sleep(interval)

        redis_key = "_".join([args.redis_prefix, key])
        message = "{0} {1}".format(redis_key, count)
        redis.publish(args.notification_channel, message)

        elapsed_time = time.time() - start_time

    log.info("program completes return code = 0")
    return 0
Exemplo n.º 4
0
    def zoom_x1(self, redis, channel, button, event=None):
        button.config(state='normal', background='orange')
        button.after(600, lambda: button.config(state='normal', background='#d9d9d9'))

        j = {'action': 'zoom_x1'}
        jstr = json.dumps(j)
        redis.publish(channel, jstr)
Exemplo n.º 5
0
 def autozoom(self, redis, channel, autozoom, event=None):
     if autozoom.get():
         j = {'action': 'autozoom', 'value': True}
     else:
         j = {'action': 'autozoom', 'value': False}
     jstr = json.dumps(j)
     redis.publish(channel, jstr)
Exemplo n.º 6
0
def inbox(ws):
    while not ws.closed:
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            redis.publish('chat', message)
Exemplo n.º 7
0
def inbox(ws):
    # flask-sockets,ws对象将被自动注入到路由处理函数
    while not ws.closed:
        message = ws.receive()

        if message:
            redis.publish('chat', message)
Exemplo n.º 8
0
def inbox(ws):
    while not ws.closed:
        message = ws.receive()

        print(message)
        if message:
            redis.publish('chat', message)
def inbox(ws):
	while not ws.closed:
		gevent.sleep(0.1)
		message=ws.receive()
	if(message):
		app.logger.info("inserting message:{}".format(message))
		redis.publish(REDIS_CHAN,message)
Exemplo n.º 10
0
def edit(request, room):
    was_private = room.is_private

    if request.method == 'POST':
        form = RoomForm(request.POST, instance=room)

        if form.is_valid():
            form.save(commit=False)
            room.save()

            if room.is_private and not was_private:
                redis = create_redis_connection()
                redis.publish('web_channel', 'room_private:' + str(room.id))
                try:
                    redis.hdel(redis_room_key(room.id), *redis.hkeys(redis_room_key(room.id)))
                except:
                    pass

            return HttpResponseRedirect(request.get_full_path())
    else:
        form = RoomForm(instance=room)

    response_data = { 'form' : form }

    if room.is_private:
        response_data['invited_users'] = room.invited.order_by('username').all()
        response_data['users'] = User.objects.exclude(pk=room.owner.id).exclude(rooms__pk=room.id).order_by('username').all()

    return response_data
Exemplo n.º 11
0
def inbox(ws):
    # Receives incoming POST requests and inserts them into Redis.
    while ws.socket is not None:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()
        redis.publish(DATABASE_BROADCASTER, message)
Exemplo n.º 12
0
def inbox(ws):
    while not ws.closed:
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            redis.publish('chat', message)
Exemplo n.º 13
0
    def exit_app(self, redis, root, event=None):
        root.destroy()
        j = {'action': 'quit'}
        jstr = json.dumps(j)

        for channel in ['uwtec:front', 'uwtec:rear', 'uwtec:side']:
            redis.publish(channel, jstr)
Exemplo n.º 14
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while not ws.closed:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            data = json.loads(message)
            
            # Get the handle
            handle = data['handle']
            # Get the message text
            humanText = data['text']
            
            # Set the session
            session = sessionID(ws)
            data['session'] = session
            # With the handle * , the message will be broadcasted
            if handle == "*":
                data['session'] = "broadcast"
            message = json.dumps(data)
            
            # Log this message
            app.logger.info(u'Inserting message by {}: {}'.format(handle, message))
            
            # Store the chat in the database
            # actor 0  =  me
            storeChat(data['session'], 0, humanText)
            redis.publish(REDIS_CHAN, message)
            
            # Have the bot prepare a response
            chatServer.bot_response(session, humanText)
Exemplo n.º 15
0
 def delete(self):
     game = Game(self.gid)
     redis.lrem(game.key(':players'), 0, self.pid)
     redis.delete(self.key(':cards'))
     redis.delete(self.key(':hand'))
     event_data = json.dumps({'action': 'leave', 'player': self.pid})
     redis.publish(game.key(':players_channel'), event_data)
Exemplo n.º 16
0
def publish(value):
    message = json.dumps({
        'id': 'worker',
        'time_stamp': str(dt.datetime.now()),
        'value': value
    })
    redis.publish(REDIS_CHAN, message)
Exemplo n.º 17
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while ws.socket is not None:
        # Sleep to prevent *contstant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()
        #print message
        #sys.stdout.flush()
	
        if message:
            jsonMessage = json.loads(message)
            #NLTK version analysis
            #message = message.replace("}", ',\"' + 'length\":\"' + str( getLengthOfMessage(message) )+ '\"' + ',\"' + 'neg\":\"' + str(getNegEmotionValue(jsonMessage["text"])) + '\"' + ',\"' + 'pos\":\"' + str(getPosEmotionValue(jsonMessage["text"])) + '\"' + '}' )
            #SentiStrength analysis
            text = jsonMessage["text"]
            sentistrength_result = RateSentiment(text)
            name = jsonMessage["handle"]
            posV = sentistrength_result[:1]
            negV = sentistrength_result[2:]
            emotionV = getEmotionValueFrom( int(posV), int(negV) )  
            message = message.replace("}", ',\"' + 'length\":\"' + str( getLengthOfMessage(message) )+ '\"' + ',\"' + 'neg\":\"' + sentistrength_result[2:] + '\"' + ',\"' + 'pos\":\"' + sentistrength_result[:1] + '\"' + '}' )


            print emotionV
            sys.stdout.flush()
            app.logger.info(u'Inserting message: {}'.format(message))
            #post the message to given channel
            redis.publish(REDIS_CHAN, message)
            chats.saveToFirebase( name, text, emotionV )
Exemplo n.º 18
0
def open():
    print('Open')
    print('Getting Json')
    req_json = request.json
    print('Got JSON', req_json)
    box_id = req_json.get('box_id')
    if not box_id:
        r = Response(response=json.dumps({
            'status': False,
            'comment': 'No Box ID'
        }),
                     status=200,
                     mimetype="application/json")
        return r
    print(db.all())
    if len(db.all()):
        print('Looking at clientss')
        response_dict = {'box_id': box_id}
        print(response_dict)
        data_string = json.dumps(response_dict)
        print('Made a response dict', data_string)
        redis.publish(REDIS_CHAN, data_string)
        return Response(response=json.dumps({'status': True}),
                        status=200,
                        mimetype="application/json")
    r = Response(response=json.dumps({'status': False}),
                 status=200,
                 mimetype="application/json")
    return r
Exemplo n.º 19
0
def index(ws):
    """
    WebSocket handler,使用一个 WebSocket 来同时处理数据发送和接收
    """

    # 注册 WebSocket 到聊天室
    chat.register(ws)

    # 新用户进入聊天室,发布一条提示消息
    redis.publish('chat', json.dumps(dict(
        username='******',
        text=len(chat.clients)
    )))

    # 如果 WebSocket 未关闭,重复进行消息接收和发送
    while not ws.closed:
        # 接收客户端消息,如果没有则阻塞在此
        message = ws.receive()
        # 客户端关闭连接时服务端会接收到一个 None 消息
        if message is None:
            break
        # 发布消息到 channel
        redis.publish('chat', message)

    # 如果 WebSocket 关闭,从聊天室里移除
    chat.unregister(ws)
Exemplo n.º 20
0
def rate_adjust():
    rate = 1.
    while rate:
        rate = raw_input('New rate >> ')
        if rate:
            rate = float(rate)
            data = {"rateAdjustFactor": rate}
            redis.publish('song-adjust', json.dumps(data))
Exemplo n.º 21
0
def inbox(ws):
    # 使用flask-sockets, ws链接对象会被自动注入到路由处理函数, 该处理函数用来处理前端发过来的消息
    
    while not ws.closed:
        message = ws.receive()
        gevent.sleep(0.1) 
        if message:
            redis.publish('chat', message)
Exemplo n.º 22
0
def outbox(ws):
    chat.register(ws)
    redis.publish('chat', json.dumps(dict(
        username='******',
        text=len(chat.clients)
    )))
    while not ws.closed:
        gevent.sleep(0.1)
Exemplo n.º 23
0
def offset_madness():
    offset = 1
    while offset:
        offset = raw_input("Add offset (ms) >> ")
        if offset:
            offset = float(offset)
            data = {"offsetInMillis": offset}
            redis.publish('song-adjust', json.dumps(data))
Exemplo n.º 24
0
 def create_player(self, user):
     pid = redis.incr(self.key(':players:next'))
     player = Player(self.gid, pid)
     player.set_username(user.username)
     redis.rpush(self.key(':players'), pid)
     event_data = json.dumps({'action': 'join', 'player': pid})
     redis.publish(self.key(':players_channel'), event_data)
     return player
Exemplo n.º 25
0
 def next_player(self):
     current_pid = self.get_current_pid()
     pids = self.get_pids()
     current_index = pids.index(current_pid)
     next_index = (current_index + 1) % len(pids)
     next_pid = pids[next_index]
     self.set_current_pid(next_pid)
     redis.publish(self.key(':current_player_channel'), next_pid)
 def send_to_redis(self, results_dataframe):
     results_json = results_dataframe.to_json(orient="records")
     for count in (json.loads(results_json)):
         # if "filter" in count.keys():
         #   filter=count["filter"]
         #   redis.publish(filter, json.dumps(count))
         # else :
         redis.publish("stream", json.dumps(count))
Exemplo n.º 27
0
def publishUsers():
    users = redis.hgetall("users")
    sortedUsers = collections.OrderedDict(sorted(users.items()))

    output_msg = ""
    for k, v in sortedUsers.items():
        output_msg += "\n" + k.decode('utf-8') + " " + v.decode('utf-8')

    redis.publish("user_list", output_msg)
Exemplo n.º 28
0
def outbox(ws):
    chat.register(ws)
    redis.publish(
        'chat',
        json.dumps(
            dict(username='******',
                 text=len(chat.clients))))
    while not ws.closed:
        gevent.sleep(0.1)
Exemplo n.º 29
0
def outbox(ws):
    chat.register(ws)
    message = {
        'username': '******',
        'text': len(chat.clients)
    }
    redis.publish('chat', json.dumps(message))
    while not ws.closed:
        gevent.sleep(0.1)
Exemplo n.º 30
0
def handle_message(message):
    data = json.loads(message)
    if data['evt'] == 'button:pressed':
        tweet = make_tweet()
        result = get_tweet_evt(tweet)
        redis.publish(REDIS_CHAN, result)
        send_tweet(tweet)
    else:
        redis.publish(REDIS_CHAN, json.dumps(data))
Exemplo n.º 31
0
def inbox(ws):
    while not ws.closed:
        if chat.notice:
            message = chat.notice
            redis.publish('chat', message)
            chat.notice = None
        message = ws.receive()
        if message:
            redis.publish('chat', message)
Exemplo n.º 32
0
def inbox(ws):
    while not ws.closed:
        gevent.sleep(0.1)
        message = ws.receive()
        print("data from ws:", message, type(message))

        if message:
            app.logger.info(u"Inserting message: {}".format(message))
            redis.publish(REDIS_CHAN, message)
Exemplo n.º 33
0
def main():
    client = KafkaClient("localhost:9092")
    consumer = SimpleConsumer(client, "test-group", "twitter_raw")
    consumer.seek(0,2)

    num = 0
    for message in consumer:
        print "redis publish:", num
        num+=1
        try:
            data_depickled = pickle.loads(message.message.value.decode('utf-8'))
        except Exception, e:
            continue
        # print data_depickled
        # {  
        #    'text':'@_LulaMoore me hamas perra',
        #    'created_at':datetime.datetime(2015, 10, 9, 23, 36, 49),
        #    'source':u'Twitter Web Client',
        #    'lang:':u'es',
        #    'place':{  
        #       'country_code':u'AR',
        #       'coordinates':[  
        #          [  
        #             -68.176283,
        #             -38.984724
        #          ],
        #          [  
        #             -68.176283,
        #             -38.921051
        #          ],
        #          [  
        #             -68.015162,
        #             -38.921051
        #          ],
        #          [  
        #             -68.015162,
        #             -38.984724
        #          ]
        #       ]
        #    },
        #    'user':{  
        #       'statuses_count':15067,
        #       'name':u'Dama negra *\uffe6*',
        #       'friends_count':390,
        #       'created_at':datetime.datetime(2014, 3, 15,2,37, 10),
        #       'profile_image_url': u'http://pbs.twimg.com/profile_images/652333268256313344/x9K9Nlys_normal.jpg',
        #       'followers_count':384,
        #       'id':2390242428
        #    },
        #    'id':652628813935980544
        # }

        ### process data here ###
        # text = data_depickled['text']
        filtered_data = data_filter(data_depickled)
        data_pickled = pickle.dumps(filtered_data)
        redis.publish('tweets_processed', data_pickled)
Exemplo n.º 34
0
def inbox(ws):
    """Recebe as mensaggens do chat e adiciona-as ao broadcast"""
    while not ws.closed:
        # sleep para evitar * constantes * context-switches..
        gevent.sleep(0.1)
        message = ws.receive()
        if message:
            print('Inserting message: {}'.format(message))
            redis.publish(REDIS_CHAN, message)
Exemplo n.º 35
0
def player_client(ws):
    while not ws.closed:
        gevent.sleep(0.1)
        message = ws.receive()

        # TODO: Validate message is legit
        if message:
            app.logger.info(u'Received command message: {}'.format(message))
            redis.publish(REDIS_COMMAND_CHAN, message)
Exemplo n.º 36
0
def radis_push_server_minute():
    redis = RedisHelper(host='127.0.0.1', port=6379)
    data = {'name': 'liwei', 'age': '30', 'sex': '1', 'addr': '深圳市南山区'}

    while True:
        j = json.dumps(data, ensure_ascii=False)
        redis.publish(j)  # 发布

        break
Exemplo n.º 37
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while not ws.closed:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            app.logger.info(u'Inserting message: {}'.format(message))
            redis.publish(REDIS_CHAN, message)
Exemplo n.º 38
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while ws.socket is not None:
        # Sleep to prevent *contstant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            app.logger.info(u'Inserting message: %s'%message)
            redis.publish(MAIN_CHAN, message)
Exemplo n.º 39
0
    def incr(self, name, timestamp=None, value=1, filters={}):
        timestamp = timestamp or datetime.datetime.now()
        try:
            redis = self.redis

            redis.sadd(self.data_key, self.serialize("incr", name, timestamp, value, filters))
            redis.publish(self.channel, json.dumps({"a": "notification"}))
        except Exception, e:
            print(e)
            logger.warn(e)
Exemplo n.º 40
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while ws.socket is not None:
        # Sleep to prevent *contstant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            app.logger.info('Inserting message: {}'.format(message.encode('utf-8')))
            redis.publish(REDIS_CHAN, message)
Exemplo n.º 41
0
 def setup(self, match):
     map_name = match.mapp.name
     redis.publish("server-%s" % self.id, json.dumps({
         "tag": "match",
         "map": map_name,
         "id": match.id,
         "players": "|".join(map(lambda i: str(convert_steamid(i.steamid)), match.getPlayers())),
         "teama": "|".join(map(lambda i: str(convert_steamid(i.steamid)), match.getTeamA())),
         "teamb": "|".join(map(lambda i: str(convert_steamid(i.steamid)), match.getTeamB()))
     }))
Exemplo n.º 42
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while not ws.closed:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            app.logger.info(u'Inserting message: {}'.format(message))
            redis.publish(REDIS_CHAN, message)
Exemplo n.º 43
0
Arquivo: app.py Projeto: accumsan/py
def inbox(ws):
    """Receives incoming messages from java, inserts them into Redis."""
    while not ws.closed:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            app.logger.info(u'Incoming message from java: {}'.format(message))
            redis.publish(REDIS_CHAN, json.dumps({'handle' : 'java', 'text':message}))
Exemplo n.º 44
0
 def _publish(action_str, user_info):
     # Broadcast that the new user has joined/left the group
     redis.publish(
         REDIS_CHAN,
         json.dumps({
             "room":
             user_info["room"],
             "msg":
             f"{user_info['username']} has {action_str} the {user_info['room']} room.",
         }))
Exemplo n.º 45
0
def inbox(ws):
    chats.register(ws)
    """Receives incoming chat messages, inserts them into Redis."""
    while ws.socket is not None:
        # Sleep to prevent *contstant* context-switches.
        message = ws.receive()
        while message:
            app.logger.info(u'Inserting message: {}'.format(message))
            redis.publish(REDIS_CHAN, message)
            message = ws.receive()
        gevent.sleep()
Exemplo n.º 46
0
    def recording(self, redis, channel, button, event=None):
        if button.config('background')[-1] == '#d9d9d9':
            button.config(state='normal', relief='raised', background='orange')
            j = {'action': 'start_recording'}
        else:
            button.config(background='#d9d9d9')
            # button.bind('<Enter>', lambda event, b=button: b.config(background='#d9d9d9'))
            j = {'action': 'stop_recording'}

        jstr = json.dumps(j)
        redis.publish(channel, jstr)
Exemplo n.º 47
0
def inbox(ws):
	while not ws.closed:
		try:
			message = ws.receive()

			if message:
				app.logger.info('Inserting message')
				redis.publish(REDIS_CHAN, message)
		except WebSocketError:
			return ''
		#  Sleep to prevent 'constant' context-switches
		gevent.sleep(0.1)
Exemplo n.º 48
0
def delete(request, room):

    redis = create_redis_connection()
    redis.publish('web_channel', 'room_deleted:' + str(room.id))
    try:
        redis.hdel(redis_room_key(room.id), *redis.hkeys(redis_room_key(room.id)))
    except:
        pass

    room.delete()

    return HttpResponseRedirect(reverse('rooms.views.my_list'))
Exemplo n.º 49
0
Arquivo: app.py Projeto: accumsan/py
def inbox(ws):
    """Receives incoming messages, inserts them into Redis."""
    while not ws.closed:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        message = ws.receive()

        if message:
            app.logger.info(u'Inserting message: {}'.format(message))
            redis.publish(REDIS_CHAN, message)
            messageObject= json.loads(message)
            redis.publish(REDIS_JAVA_CHAN, "Hey java ! Message from python : " + messageObject["text"])
Exemplo n.º 50
0
def inbox(ws):
    """Receives incoming chat messages, inserts them into Redis."""
    while not ws.closed:
        # Sleep to prevent *constant* context-switches.
        gevent.sleep(0.1)
        raw_message = ws.receive()

        if raw_message:
            app.logger.info(u'Inserting message: {}'.format(raw_message))
            message = json.loads(raw_message)
            result = process_message(message)
            if result is not None:
                redis.publish(REDIS_CHAN, json.dumps(result))
Exemplo n.º 51
0
 def get(self,item_id=None):
     if item_id is None:
         # list entire table
         rtn = [x.to_json() for x in Photo.get_all()]
         for itm in rtn:
             redis.publish('list_view',itm)
     else:
         rtn = [x.to_json() for x in Photo.get_all() if x.group_id == item_id]
         for itm in rtn:
             redis.publish('list_view_{0}'.format(item_id),itm)
     res = flask.make_response(json.dumps(rtn))
     res.headers['Content-Type'] = 'application/json'
     return res
Exemplo n.º 52
0
    def on_msg(self, tweet):

        if tweet['lang'] == 'en':
            if 'entities' in tweet and 'hashtags' in tweet['entities']:
                tags = tweet['entities']['hashtags']
                for tag in tags:
                    elem = tag['text']
                    # self.algorithm.computeHeavyHitter(elem)
                    self.algorithm.computeSketch(elem)
                    print(elem, self.algorithm.getSketchFor(elem))
                    redis.publish('hashtag_count', elem)
                    self.streamDrillUpdater.update(elem)
        return
Exemplo n.º 53
0
 def startQueue(self):
     if self.state == LobbyState.LOBBY_STATE_SEARCH: return
     self.state = LobbyState.LOBBY_STATE_SEARCH
     self.queuedat = datetime.utcnow()
     self.save()
     self.sendAction({
         "type": "state",
         "state": self.state,
         "msg": "Queue started"
     })
     redis.publish("lobby-queue", json.dumps({
         "tag": "match",
         "id": self.id
     }))
Exemplo n.º 54
0
def delete_invite(request, room, user_id):
    if room.is_private:
        user = get_object_or_404(User, pk=user_id)

        redis = create_redis_connection()
        redis.publish('web_channel', 'kick_user_from_room:' + str(room.id) + ':' + str(user.id))
        session_key = redis.get('session_key:' + str(user.id))
        try:
            redis.hdel(redis_room_key(room.id), session_key)
        except:
            pass

        room.invited.remove(user)

    return HttpResponseRedirect(reverse('rooms.views.edit', args=[room.id]))
Exemplo n.º 55
0
def notify_subscribers(draad, post):
  """ Given a ForumDraad instance `draad`, notify all subscribers of `post`
  """

  for profiel_id, auth_id in draad.subscribers.all().values_list('user__pk', 'user__user__pk'):
    # don't notify the poster
    if profiel_id == post.user.pk: continue

    # push the event into the user's notification channel on the redis cluster
    key = "notifications:" + str(auth_id)
    redis.publish(key, {
      'draad': ShortForumDraadSerializer(draad).data,
      'post': {
        'user': ShortProfielSerializer(post.user).data,
        'tekst': post.tekst
      }
    })