def post(self): params = utils.decode_params(self.request) resp = {} result = True if KEY.OPERATION in params and params[KEY.OPERATION] == 0: result = db.remove_static_relation(params) elif KEY.OPERATION in params and params[KEY.OPERATION] == 1: result = db.add_static_relation(params) '''send the tongtou message to tell the user''' user_info = db.get_user_information({KEY.ID: params[KEY.ID]}) user_acc = db.get_user_information({KEY.ID: params[KEY.USER_ID]}) user_info = utils.trans_unicode_to_utf(user_info) user_acc = utils.trans_unicode_to_utf(user_acc) mess_package = {KEY.USER_ID: user_info[KEY.ID], KEY.NICKNAME: user_info[KEY.NICKNAME],\ KEY.REALNAME: user_info[KEY.NAME], KEY.LOCATION: user_info[KEY.LOCATION], KEY.OCCUPATION: user_info[KEY.OCCUPATION]} mess_package[KEY.TYPE] = params[KEY.TYPE] mess_package['message-type'] = 4 if KEY.CONTENT in params: mess_package[KEY.CONTENT] = params[KEY.CONTENT] mess = sendHelp.buildMessage(custom=mess_package) print sendHelp.sendEhelp(header + user_acc[KEY.NICKNAME], mess) else: result = False if result: resp[KEY.STATUS] = STATUS.OK else: resp[KEY.STATUS] = STATUS.ERROR self.write(json_encode(resp))
def post(self): params = utils.decode_params(self.request) resp = {} answer_id = db.add_answer(params) if answer_id == -1: resp[KEY.STATUS] = STATUS.ERROR else: resp[KEY.STATUS] = STATUS.OK event_info = db.get_event_information({KEY.EVENT_ID: params[KEY.EVENT_ID]}) user_info = db.get_user_information({KEY.ID: event_info[KEY.LAUNCHER_ID]}) user_info = utils.trans_unicode_to_utf(user_info) event_info = utils.trans_unicode_to_utf(event_info) is_like = 0 if db.is_user_like_event({KEY.ID: event_info[KEY.LAUNCHER_ID], KEY.EVENT_ID: params[KEY.EVENT_ID]}): is_like = 1 custom = {KEY.EVENT_ID: params[KEY.EVENT_ID], KEY.NICKNAME: user_info[KEY.NICKNAME], KEY.TIME: event_info[KEY.TIME], KEY.TITLE: event_info[KEY.TITLE], \ KEY.CONTENT: event_info[KEY.CONTENT], KEY.LOVE_COIN: event_info[KEY.LOVE_COIN], KEY.FOLLOW_NUMBER: event_info[KEY.FOLLOW_NUMBER],\ KEY.SUPPORT_NUMBER: event_info[KEY.SUPPORT_NUMBER], KEY.IS_LIKE: is_like} custom['message-type'] = 5 mess = sendHelp.buildMessage(type=1, title=title, content=content, style=style, action=action, custom=custom) print sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) '''and send the tongyou message''' mess = sendHelp.buildMessage(custom=custom) print sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) resp[KEY.ANSWER_ID] = answer_id self.write(json_encode(resp))
def post(self): params = utils.decode_params(self.request) resp = {} result = True if KEY.OPERATION in params and params[KEY.OPERATION] == 0: result = db.remove_static_relation(params) elif KEY.OPERATION in params and params[KEY.OPERATION] == 1: result = db.add_static_relation(params) '''send the tongtou message to tell the user''' user_info = db.get_user_information({KEY.ID: params[KEY.ID]}) user_acc = db.get_user_information({KEY.ID: params[KEY.USER_ID]}) user_info = utils.trans_unicode_to_utf(user_info) user_acc = utils.trans_unicode_to_utf(user_acc) mess_package = {KEY.USER_ID: user_info[KEY.ID], KEY.NICKNAME: user_info[KEY.NICKNAME],\ KEY.REALNAME: user_info[KEY.NAME], KEY.LOCATION: user_info[KEY.LOCATION], KEY.OCCUPATION: user_info[KEY.OCCUPATION]} mess_package[KEY.TYPE] = params[KEY.TYPE] mess_package['message-type'] = 4 if KEY.CONTENT in params: mess_package[KEY.CONTENT] = params[KEY.CONTENT] mess = sendHelp.buildMessage(custom=mess_package) print sendHelp.sendEhelp(header + user_acc[KEY.NICKNAME], mess) else: result = False if result: resp[KEY.STATUS] = STATUS.OK else: resp[KEY.STATUS] = STATUS.ERROR self.write(json_encode(resp))
def post(self): params = utils.decode_params(self.request) if KEY.ID not in params or KEY.EVENT_ID not in params or KEY.ANSWER_ID not in params: self.write(json_encode(resp)) return resp = {} params[KEY.IS_ADOPTED] = 1 result = db.update_answer(params) if result is True: resp[KEY.STATUS] = STATUS.OK event_info = db.get_event_information( {KEY.EVENT_ID: params[KEY.EVENT_ID]}) user_info = db.get_user_information( {KEY.ID: event_info[KEY.LAUNCHER_ID]}) answer_info = db.get_answer_info( {KEY.ANSWER_ID: params[KEY.ANSWER_ID]}) user_info = utils.trans_unicode_to_utf(user_info) event_info = utils.trans_unicode_to_utf(event_info) answer_info = utils.trans_unicode_to_utf(answer_info) is_like = 0 if db.is_user_like_event({ KEY.ID: event_info[KEY.LAUNCHER_ID], KEY.EVENT_ID: params[KEY.EVENT_ID] }): is_like = 1 custom = {KEY.EVENT_ID: params[KEY.EVENT_ID], KEY.NICKNAME: user_info[KEY.NICKNAME], KEY.LAUNCHER: answer_info[KEY.AUTHOR].encode('UTF-8'), \ KEY.TIME: event_info[KEY.TIME], KEY.TITLE: event_info[KEY.TITLE], \ KEY.CONTENT: event_info[KEY.CONTENT], KEY.LOVE_COIN: event_info[KEY.LOVE_COIN], KEY.FOLLOW_NUMBER: event_info[KEY.FOLLOW_NUMBER],\ KEY.SUPPORT_NUMBER: event_info[KEY.SUPPORT_NUMBER], KEY.IS_LIKE: is_like} custom['message-type'] = 7 mess = sendHelp.buildMessage(type=1, title=title, content=content, style=style, action=action, custom=custom) sendHelp.sendEhelp( header + answer_info[KEY.AUTHOR].encode('UTF-8'), mess) mess = sendHelp.buildMessage(custom=custom) sendHelp.sendEhelp( header + answer_info[KEY.AUTHOR].encode('UTF-8'), mess) else: resp[KEY.STATUS] = STATUS.ERROR self.write(json_encode(resp))
def post(self): params = {} resp = {KEY.STATUS: 500} params = utils.decode_params(self.request) if KEY.ID not in params or KEY.EVENT_ID not in params or KEY.LAUNCHER_ID not in params or KEY.TYPE not in params: self.write(json_encode(resp)) return '''trans the term's type''' params[KEY.ID] = int(params[KEY.ID]) params[KEY.EVENT_ID] = int(params[KEY.EVENT_ID]) params[KEY.LAUNCHER_ID] = int(params[KEY.LAUNCHER_ID]) params[KEY.TYPE] = int(params[KEY.TYPE]) flag = db.add_support_relation(params) if flag >= 0: resp[KEY.STATUS] = 200 '''send notification to supportee, someone is coming to help him''' launcher_info = db.get_user_information({KEY.ID: params[KEY.LAUNCHER_ID]}) launcher_info = utils.trans_unicode_to_utf(launcher_info) if launcher_info is not None: if params[KEY.TYPE] == 2: mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style(0, 0, 0, 1, 2)) sendHelp.sendEhelp(header + launcher_info[KEY.NICKNAME], mess) if params[KEY.TYPE] == 1: mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style(0, 0, 0, 0, 5)) sendHelp.sendEhelp(header + launcher_info[KEY.NICKNAME], mess) self.write(json_encode(resp))
def post(self): params = {} resp = {KEY.STATUS: 500} params = utils.decode_params(self.request) if KEY.ID not in params or KEY.LAUNCHER_ID not in params or KEY.TYPE not in params or KEY.EVENT_ID not in params: self.write(json_encode(resp)) return '''trans the term's type''' params[KEY.EVENT_ID] = int(params[KEY.EVENT_ID]) params[KEY.ID] = int(params[KEY.ID]) params[KEY.LAUNCHER_ID] = int(params[KEY.LAUNCHER_ID]) params[KEY.TYPE] = int(params[KEY.TYPE]) flag = db.remove_support_relation(params) if flag: '''when the event is help or emergence, it is necessary to notify the users''' user_info = db.get_user_information({KEY.ID: params[KEY.LAUNCHER_ID]}) user_info = utils.trans_unicode_to_utf(user_info) if user_info is not None: if params[KEY.TYPE] == 2: mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style(0, 0, 0, 1, 3)) sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) if params[KEY.TYPE] == 1: mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style(0, 0, 0, 0, 6)) sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) resp[KEY.STATUS] = 200 self.write(json_encode(resp))
def post(self): params = {} resp = {KEY.STATUS: 500} params = utils.decode_params(self.request) if KEY.ID not in params or KEY.EVENT_ID not in params: self.write(json_encode(resp)) return '''trans the term's type''' params[KEY.ID] = int(params[KEY.ID]) params[KEY.EVENT_ID] = int(params[KEY.EVENT_ID]) event_info = db.get_event_information(params) if event_info is not None: if event_info[KEY.LAUNCHER_ID] == params[KEY.ID]: resp[KEY.STATUS] = 200 params[KEY.STATE] = 1 if not db.update_event(params): resp[KEY.STATUS] = 500 else: '''send a notification to notice the user. all supporters''' supporter_ids = db.list_support_relation({KEY.EVENT_ID: params[KEY.EVENT_ID]}) if supporter_ids is not None: resp[KEY.STATUS] = 200 for item in supporter_ids: user_info = db.get_user_information({KEY.ID: item}) user_info = utils.trans_unicode_to_utf(user_info) mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style(0, 0, 0, 1, 3)) sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) mess = sendHelp.buildMessage(custom={'message-type': 2}) sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) self.write(json_encode(resp))
def post(self): params = utils.decode_params(self.request) resp = {} result = db.handle_static_relation(params) if result is True: resp[KEY.STATUS] = STATUS.OK user_info = db.get_user_information({KEY.ID: params[KEY.ID]}) user_acc = db.get_user_information({KEY.ID: params[KEY.USER_ID]}) user_acc = utils.trans_unicode_to_utf(user_acc) custom = {'message-type': 5, KEY.STATUS: params[KEY.OPERATION], KEY.NICKNAME: user_info[KEY.NICKNAME]} custom = utils.trans_unicode_to_utf(custom) mess = sendHelp.buildMessage(custom=custom) sendHelp.sendEhelp(KEY.HEADER + user_acc[KEY.NICKNAME], mess) else: resp[KEY.STATUS] = STATUS.ERROR self.write(json_encode(resp))
def post(self): params = utils.decode_params(self.request) resp = {} result = db.handle_static_relation(params) if result is True: resp[KEY.STATUS] = STATUS.OK user_info = db.get_user_information({KEY.ID: params[KEY.ID]}) user_acc = db.get_user_information({KEY.ID: params[KEY.USER_ID]}) user_acc = utils.trans_unicode_to_utf(user_acc) custom = {'message-type': 5, KEY.STATUS: params[KEY.OPERATION], KEY.NICKNAME: user_info[KEY.NICKNAME]} custom = utils.trans_unicode_to_utf(custom) mess = sendHelp.buildMessage(custom=custom) sendHelp.sendEhelp(KEY.HEADER + user_acc[KEY.NICKNAME], mess) else: resp[KEY.STATUS] = STATUS.ERROR self.write(json_encode(resp))
def post(self): params = utils.decode_params(self.request) resp = {} answer_id = db.add_answer(params) if answer_id == -1: resp[KEY.STATUS] = STATUS.ERROR else: resp[KEY.STATUS] = STATUS.OK event_info = db.get_event_information( {KEY.EVENT_ID: params[KEY.EVENT_ID]}) user_info = db.get_user_information( {KEY.ID: event_info[KEY.LAUNCHER_ID]}) helper_info = db.get_user_information({KEY.ID: params[KEY.ID]}) user_info = utils.trans_unicode_to_utf(user_info) helper_info = utils.trans_unicode_to_utf(helper_info) event_info = utils.trans_unicode_to_utf(event_info) is_like = 0 if db.is_user_like_event({ KEY.ID: event_info[KEY.LAUNCHER_ID], KEY.EVENT_ID: params[KEY.EVENT_ID] }): is_like = 1 custom = {KEY.EVENT_ID: params[KEY.EVENT_ID], KEY.NICKNAME: helper_info[KEY.NICKNAME], KEY.LAUNCHER: user_info[KEY.NICKNAME], KEY.TIME: event_info[KEY.TIME], KEY.TITLE: event_info[KEY.TITLE], \ KEY.CONTENT: event_info[KEY.CONTENT], KEY.LOVE_COIN: event_info[KEY.LOVE_COIN], KEY.FOLLOW_NUMBER: event_info[KEY.FOLLOW_NUMBER],\ KEY.SUPPORT_NUMBER: event_info[KEY.SUPPORT_NUMBER], KEY.IS_LIKE: is_like} custom['message-type'] = 5 mess = sendHelp.buildMessage(type=1, title=title, content=content, style=style, action=action, custom=custom) sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) '''and send the tongyou message''' mess = sendHelp.buildMessage(custom=custom) sendHelp.sendEhelp(header + user_info[KEY.NICKNAME], mess) resp[KEY.ANSWER_ID] = answer_id self.write(json_encode(resp))
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 post(self): params = {} resp = {KEY.STATUS: 500} params = utils.decode_params(self.request) if KEY.ID not in params or KEY.EVENT_ID not in params: self.write(json_encode(resp)) return '''trans the term's type''' params[KEY.ID] = int(params[KEY.ID]) params[KEY.EVENT_ID] = int(params[KEY.EVENT_ID]) event_info = db.get_event_information(params) if event_info is not None: if event_info[KEY.LAUNCHER_ID] == params[KEY.ID]: resp[KEY.STATUS] = 200 params[KEY.STATE] = 2 if not db.update_event(params): resp[KEY.STATUS] = 500 else: '''send notification to the people who is coming to help him''' supporter_ids = db.list_support_relation( {KEY.EVENT_ID: params[KEY.EVENT_ID]}) if supporter_ids is not None: for item in supporter_ids: user_info = db.get_user_information({KEY.ID: item}) user_info = utils.trans_unicode_to_utf(user_info) if user_info is not None: mess = sendHelp.buildMessage( type=1, title=title, content=content, style=style, custom={KEY.EVENT_ID: params[KEY.EVENT_ID]}) sendHelp.sendEhelp( header + user_info[KEY.NICKNAME], mess) '''send tongtou message to android''' mess = sendHelp.buildMessage( custom={'message-type': 3}) sendHelp.sendEhelp( header + user_info[KEY.NICKNAME], mess) self.write(json_encode(resp))
def post(self): params = {} resp = {KEY.STATUS: 500} params = utils.decode_params(self.request) if KEY.ID not in params or KEY.EVENT_ID not in params or KEY.LAUNCHER_ID not in params or KEY.TYPE not in params: self.write(json_encode(resp)) return '''trans the term's type''' params[KEY.ID] = int(params[KEY.ID]) params[KEY.EVENT_ID] = int(params[KEY.EVENT_ID]) params[KEY.LAUNCHER_ID] = int(params[KEY.LAUNCHER_ID]) params[KEY.TYPE] = int(params[KEY.TYPE]) flag = db.add_support_relation(params) if flag >= 0: resp[KEY.STATUS] = 200 '''send notification to supportee, someone is coming to help him''' launcher_info = db.get_user_information( {KEY.ID: params[KEY.LAUNCHER_ID]}) launcher_info = utils.trans_unicode_to_utf(launcher_info) if launcher_info is not None: if params[KEY.TYPE] == 2: mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style( 0, 0, 0, 1, 2)) sendHelp.sendEhelp(header + launcher_info[KEY.NICKNAME], mess) if params[KEY.TYPE] == 1: mess = sendHelp.buildMessage(type=1, title=title, content=content, style=xinge.Style( 0, 0, 0, 0, 5)) sendHelp.sendEhelp(header + launcher_info[KEY.NICKNAME], mess) self.write(json_encode(resp))