Пример #1
0
    def post(self):
        params = {}
        resp = {KEY.STATUS: 500}
        params = utils.decode_params(self.request)
        if KEY.ID not in params or KEY.TYPE not in params:
            self.write(json_encode(resp))
            return
        params[KEY.TYPE] = int(params[KEY.TYPE])
        if KEY.TITLE not in params or KEY.CONTENT not in params or KEY.LOVE_COIN not in params:
            self.write(json_encode(resp))
            return
        if params[KEY.TYPE] == 1:
            if KEY.LONGITUDE not in params or KEY.LATITUDE not in params or KEY.DEMAND_NUMBER not in params:
                self.write(json_encode(resp))
                return
            else:
                params[KEY.DEMAND_NUMBER] = int(params[KEY.DEMAND_NUMBER])
        '''trans the term's type'''
        params[KEY.ID] = int(params[KEY.ID])
        params[KEY.LOVE_COIN] = int(params[KEY.LOVE_COIN])
        params[KEY.LATITUDE] = float(params[KEY.LATITUDE])
        params[KEY.LONGITUDE] = float(params[KEY.LONGITUDE])
        '''add event'''
        flag = db.add_event(params)
        if flag > 0:
            resp[KEY.STATUS] = 200
            resp[KEY.EVENT_ID] = flag
            '''spread the message to the people nearby'''
            '''if the event is help, then spread the notification'''
            user_list = db.get_nearby_people(params)
            people_nearby_sum = 0
            for item in user_list:
                item = item.encode('UTF-8')
                if params[KEY.TYPE] == 1:
                    mess = sendHelp.buildMessage(type=1,
                                                 title=title,
                                                 content=content,
                                                 style=style,
                                                 action=action,
                                                 custom={
                                                     KEY.EVENT_ID: flag,
                                                     KEY.TYPE: 1
                                                 })
                    sendHelp.sendEhelp(header + item, mess)
                if params[KEY.TYPE] == 0:
                    mess = sendHelp.buildMessage(custom={'message-type': 1})
                    sendHelp.sendEhelp(header + item, mess)
                people_nearby_sum += 1

        self.write(json_encode(resp))
    def post(self):
        params = utils.decode_params(self.request)

        resp = {}
        event_id = db.add_event(params)
        if event_id > 0:
            event_info = {}
            event_info[KEY.EVENT_ID] = event_id
            resp = db.get_question_information(event_info)
            if resp is None:
                resp = {}
            resp[KEY.STATUS] = STATUS.OK
        else:
            resp[KEY.STATUS] = STATUS.ERROR
Пример #3
0
    def post(self):
        params = utils.decode_params(self.request)

        resp = {}
        event_id = db.add_event(params)
        if event_id > 0:
            event_info = {}
            event_info[KEY.EVENT_ID] = event_id
            resp = db.get_event_information(event_info)
            if resp is None:
                resp = {}
            resp[KEY.STATUS] = STATUS.OK
        else:
            resp[KEY.STATUS] = STATUS.ERROR

        self.write(json_encode(resp))
Пример #4
0
    def post(self):
        params = {}
        resp = {KEY.STATUS: 500}
        params = utils.decode_params(self.request)
        if KEY.ID not in params or KEY.TYPE not in params or KEY.LONGITUDE not in params or KEY.LATITUDE not in params:
            self.write(json_encode(resp))
            return
        
        '''trans the term's type'''
        params[KEY.ID] = int(params[KEY.ID])
        params[KEY.LATITUDE] = float(params[KEY.LATITUDE])
        params[KEY.LONGITUDE] = float(params[KEY.LONGITUDE])
        params[KEY.TYPE] = int(params[KEY.TYPE])

        '''add emergent event'''
        flag = db.add_event(params)
        if flag > 0:
            resp[KEY.STATUS] = 200
            resp[KEY.EVENT_ID] = flag
            '''put message to the people nearby'''
            user_list = db.get_nearby_people(params)
            people_nearby_sum = 0
            launcher_info = db.get_user_information({KEY.ID: params[KEY.ID]})
            launcher_info = utils.trans_unicode_to_utf(launcher_info)
            if user_list.count(launcher_info[KEY.NICKNAME]) > 0:
                user_list.remove(launcher_info[KEY.NICKNAME])
                mess = sendHelp.buildMessage(type=1, title=title, content=content1, style=style1)
                sendHelp.sendEhelp(header + launcher_info[KEY.NICKNAME], mess)

            for item in user_list:
                item = item.encode('UTF-8')
                mess = sendHelp.buildMessage(type=1, title=title, content=content, style=style, action=action, custom={KEY.EVENT_ID: flag})    
                sendHelp.sendEhelp(header + item, mess)
                people_nearby_sum += 1
            
            '''
               here we can enhance it, if the people_nearby_sum = 0, we can change the range and send the message
            '''

            '''
               here we can improve it, meanwhile, send message to the emergent contact.
            '''

        self.write(json_encode(resp))
    def on_message(self, message):
        mes = tornado.escape.json_decode(message)
        mes[KEY.ID] = int(mes[KEY.ID])

        '''indicate the status of create comment or question'''
        mes["resp_status"] = 200
        
        mes[KEY.TYPE] = 0


        '''to show the current time, but the format must be consistent with the database'''
        mes["date"] = time.asctime(time.localtime(time.time()))

        if mes["mesType"] == 0:

            mes[KEY.LOVE_COIN] = int(mes[KEY.LOVE_COIN]) #debug
            eventId = db.add_event(mes)

            if eventId > 0:

                mes["eventId"] = eventId


                SocketCommentHandler.send_to_all(mes)
            else:
                mes["resp_status"] = 500

                #debug
                #有错误时 把错误发给当前的websocket
                self.write_message(json.dumps(mes))
                #SocketCommentHandler.send_to_all(mes)
        
        #这是评论
        if mes["mesType"] == 1:


            mes["event_id"] = int(mes["event_id"])
            mes["parent_author"] = int(mes["author_id"])

            if db.add_comment(mes) > 0:

                SocketCommentHandler.send_to_all(mes)
            else:
                mes["resp_status"] = 500
Пример #6
0
    def post(self):
        params = {}
        resp = {KEY.STATUS: 500}
        params = utils.decode_params(self.request)
        if KEY.ID not in params or KEY.TYPE not in params:
            self.write(json_encode(resp))
            return
        params[KEY.TYPE] = int(params[KEY.TYPE])
        if KEY.TITLE not in params or KEY.CONTENT not in params or KEY.LOVE_COIN not in params:
            self.write(json_encode(resp))
            return
        if params[KEY.TYPE] == 1:
            if KEY.LONGITUDE not in params or KEY.LATITUDE not in params or KEY.DEMAND_NUMBER not in params:
                self.write(json_encode(resp))
                return
            else:
                params[KEY.DEMAND_NUMBER] = int(params[KEY.DEMAND_NUMBER])
        
        '''trans the term's type'''
        params[KEY.ID] = int(params[KEY.ID])
        params[KEY.LOVE_COIN] = int(params[KEY.LOVE_COIN])
        params[KEY.LATITUDE] = float(params[KEY.LATITUDE])
        params[KEY.LONGITUDE] = float(params[KEY.LONGITUDE])
        '''add event'''
        flag = db.add_event(params)
        if flag > 0:
            resp[KEY.STATUS] = 200
            resp[KEY.EVENT_ID] = flag

            '''spread the message to the people nearby'''
            '''if the event is help, then spread the notification'''
            user_list = db.get_nearby_people(params)
            people_nearby_sum = 0
            for item in user_list:
                item = item.encode('UTF-8')
                if params[KEY.TYPE] == 1:
                    mess = sendHelp.buildMessage(type=1, title=title, content=content, style=style, action=action, custom={KEY.EVENT_ID: flag, KEY.TYPE: 1})
                    sendHelp.sendEhelp(header + item, mess)
                if params[KEY.TYPE] == 0:
                    mess = sendHelp.buildMessage(custom={'message-type': 1})
                    sendHelp.sendEhelp(header + item, mess)
                people_nearby_sum += 1

        self.write(json_encode(resp))
Пример #7
0
  def post(self):
    params = utils.decode_params(self.request)
    
    resp = {}
    event_id = db.add_event(params)
    if event_id > 0:
      event_info = {}
      event_info[KEY.EVENT_ID] = event_id
      resp[KEY.VALUE] = db.get_event_information(event_info)
      if resp is None:
        resp = {}      
      resp[KEY.STATUS] = STATUS.OK
    else:
      resp[KEY.STATUS] = STATUS.ERROR
      if event_id == -1:
        resp[KEY.VALUE] = -1
      if event_id == -2:
        resp[KEY.VALUE] = -2

    
    self.write(json_encode(resp))
    def on_message(self, message):
        mes = tornado.escape.json_decode(message)
        mes[KEY.ID] = int(mes[KEY.ID])
        '''indicate the status of create comment or question'''
        mes["resp_status"] = 200

        mes[KEY.TYPE] = 0
        '''to show the current time, but the format must be consistent with the database'''
        mes["date"] = time.asctime(time.localtime(time.time()))

        if mes["mesType"] == 0:

            mes[KEY.LOVE_COIN] = int(mes[KEY.LOVE_COIN])  #debug
            eventId = db.add_event(mes)

            if eventId > 0:

                mes["eventId"] = eventId

                SocketCommentHandler.send_to_all(mes)
            else:
                mes["resp_status"] = 500

                #debug
                #有错误时 把错误发给当前的websocket
                self.write_message(json.dumps(mes))
                #SocketCommentHandler.send_to_all(mes)

        #这是评论
        if mes["mesType"] == 1:

            mes["event_id"] = int(mes["event_id"])
            mes["parent_author"] = int(mes["author_id"])

            if db.add_comment(mes) > 0:

                SocketCommentHandler.send_to_all(mes)
            else:
                mes["resp_status"] = 500
Пример #9
0
  def post(self):
    params = utils.decode_params(self.request)
    
    resp = {}
    event_id = db.add_event(params)
    print "From add_event_handler: event id: %d"%event_id
    if event_id > 0:
      # update location in Baidu LBS Cloud
      baiduResult = baidulbs.update_location(params, KEY.EVENT)

      event_info = {}
      event_info[KEY.EVENT_ID] = event_id
      resp = db.get_event_information(event_info)
      if resp is None:
        resp = {}
      else:
        #print resp
        # get a near users' id list of current event
        near_list = baidulbs.get_user_location(resp)
        # get correspond push_token to user id
        token_list = db.get_push_token(near_list)

        # if there are tokens, push to those user
        if token_list is not None or token_list != []:
          if resp[KEY.TYPE] == 1:
            title = "New Help"
            activity = ""
            content = resp[KEY.CONTENT]
            utils.push_message(title, content, event_id, KEY.SENDALL, token_list)
          elif resp[KEY.TYPE] == 2:
            title = "New SOS"
            activity = ""
            content = resp[KEY.CONTENT]
            utils.push_message(title, content, event_id, KEY.SENDALL, token_list)
      resp[KEY.STATUS] = STATUS.OK
    else:
      resp[KEY.STATUS] = STATUS.ERROR
    
    self.write(json_encode(resp))