コード例 #1
0
    def on_data(self, data):
        """
        When data comes in, parse and broadcast the information we care about.

        :param data: JSON returned by Twitter's API.
        :type data: JSON
        :return: bool
        """
        data = json.loads(data)

        params = {
            'created_at': data.get('created_at'),
            'user': data.get('user').get('screen_name'),
            'tweet': data.get('text'),
            'type': self._parse_type(data)
        }

        logging.info(params)

        if self.broadcast:
            Broadcast.message('/cats', params,
                              internal_url=self.broadcast_internal_url,
                              push_token=self.broadcast_push_token)

        return True
コード例 #2
0
def broadcast_message(internal_url, data):
    """
    Broadcast the message to anyone listening. We are rate limiting the tweets
    because otherwise it's nearly impossible to read.

    :param internal_url: Full internal websocket URL
    :type internal_url: str
    :param data: Final data to be sent to the websocket server
    :type data: JSON
    :return: None
    """
    # Fix circular import issues.
    from catwatch.blueprints.stream.broadcast import Broadcast

    Broadcast.send_to_websocket_server(internal_url, data)
コード例 #3
0
def broadcast_message(internal_url, data):
    """
    Broadcast the message to anyone listening. We are rate limiting the tweets
    because otherwise it's nearly impossible to read.

    :param internal_url: Full internal websocket URL
    :type internal_url: str
    :param data: Final data to be sent to the websocket server
    :type data: JSON
    :return: None
    """
    # Fix circular import issues.
    from catwatch.blueprints.stream.broadcast import Broadcast

    Broadcast.send_to_websocket_server(internal_url, data)