Beispiel #1
0
    def on_message(self, data):
        """
        Callback when new message received vie the socket.
        """

        logging.info('Received new message %r', data)
        try:
            # Parse input to message dict.
            datadecoded = tornado.escape.json_decode(data)
            sen = 0;
            sen = sentiment_score(tornado.escape.linkify(datadecoded["body"]))
            G = (255 * sen)
            R = (255 * (1 - sen))
            B=0
            if len(datadecoded["body"]) < 2:
                R=255
                G=255
                B=255

            message = {
                '_id': ''.join(random.choice(string.ascii_uppercase) for i in range(12)),
                'from': self.get_cookie('SentiUser', str(datadecoded['user'])),
                    # str(self.get_cookie('SentiUser')),

                'body': tornado.escape.linkify(datadecoded["body"]),
                'sentiment': 'rgb('+str(int(R))+','+str(int(G))+','+str(int(B))+'); ',
            }
            if not message['from']:
                logging.warning("Error: Authentication missing")
                message['from'] = 'Guest'
        except Exception, err:
            # Send an error back to client.
            self.write_message({'error': 1, 'textStatus': 'Bad input data ... ' + str(err) + data})
            return
Beispiel #2
0
import tornado.auth
import tornado.options
import tornado.escape
from tornado import gen

# Redis modules.
import brukva

# Import application modules.
from base import BaseHandler
from auth import LoginHandler
from auth import LogoutHandler


from sent.sentiment import sentiment_score
print( sentiment_score("go die"))









# Define port from command line parameter.
tornado.options.define("port", default=8888, help="run on the given port", type=int)



class MainHandler(BaseHandler):