def fake_broadcast():
    """
    Broadcast fake events (useful for testing).

    :return: None
    """
    fake = Faker()

    while True:
        random_types = ('tweet', 'retweet', 'favorite')
        random_tweet = fake.text(max_nb_chars=140)

        data = {
            'created_at': str(datetime.datetime.now(pytz.utc)),
            'type': random.choice(random_types),
            'tweet': random_tweet,
            'user': fake.user_name()
        }

        faye_protocol = {
            'channel': '/cats',
            'data': data,
            'ext': {
                'pushToken': BROADCAST_PUSH_TOKEN
            }
        }

        broadcast_message.delay(BROADCAST_INTERNAL_URL, faye_protocol)
        logging.info(data)
        sleep(1)

    return None
def fake_broadcast():
    """
    Broadcast fake events (useful for testing).

    :return: None
    """
    fake = Faker()

    while True:
        random_types = ('tweet', 'retweet', 'favorite')
        random_tweet = fake.text(max_nb_chars=140)

        data = {
            'created_at': str(datetime.datetime.now(pytz.utc)),
            'type': random.choice(random_types),
            'tweet': random_tweet,
            'user': fake.user_name()
        }

        faye_protocol = {
            'channel': '/cats',
            'data': data,
            'ext': {
                'pushToken': BROADCAST_PUSH_TOKEN
            }
        }

        broadcast_message.delay(BROADCAST_INTERNAL_URL, faye_protocol)
        logging.info(data)
        sleep(1)

    return None
示例#3
0
    def message(cls, channel, data, internal_url=None, push_token=None):
        """
        Put together a message that will be sent over websockets.

        :param channel: Channel name
        :type channel: str
        :param data: Data to be sent to the websocket server
        :type data: JSON
        :param internal_url: Full internal websocket URL
        :type internal_url: str
        :param push_token: Push token used when broadcasting the message
        :type push_token: str
        :return: dict
        """
        faye_protocol = {
            'channel': channel,
            'data': data,
            'ext': {
                'pushToken': push_token
            }
        }

        broadcast_message.delay(internal_url, faye_protocol)

        return faye_protocol