def post(self): to_name = self.get_argument('to', None) text = self.get_argument('text', None) picture = self.get_argument('picture', None) from_name = self.current_user message = {'text': text, 'picture': picture, 'date': time.time()} self.rds.new_message(from_name, to_name, json_dumps(message)) pub_msg = {'from': from_name, 'to': to_name} pub_msg.update(message) self.rds.publish(self.rds.SUBJECT_NEW_MESSAGE, json_dumps(pub_msg)) self.write('Got new message.')
def post(self): message = self.get_argument('text', ' ') picture = self.get_argument('picture', None) me = self.current_user # Save message from me to Robot. human_msg = {'text': message, 'picture': picture, 'date': time.time()} self.rds.new_message(me, 'Robot', json_dumps(human_msg)) sql = 'select id from users where username=%s' userid = yield self.async_task(self.db.get, sql, me) response = yield self.async_task(robot.get, message, userid) if picture: picture = '<b>不要发图片给我,亲!</b>' # Save message from Robot to me. robot_msg = {'text': response, 'picture': picture, 'date': time.time()} self.rds.new_message('Robot', me, json_dumps(robot_msg)) # Publish message from Robot to me. pub_msg = {'from': 'Robot', 'to': me} pub_msg.update(robot_msg) self.rds.publish(self.rds.SUBJECT_NEW_MESSAGE, json_dumps(pub_msg)) self.write('Got new message.')