def update(group_id, id): if request.method == 'GET': message = MessageModel.find_by_id(_id=id, group_id=group_id) if message is None: flash( 'The scheduled message is already executed or does not exists.' ) return redirect(url_for('dashboard.index')) group = GroupModel.find_by_id(group_id).json() return render_template('dashboard/update.html', message=message, group_name=group['channel']['group_name']) if request.method == "POST": group_id = int(group_id) schedule = parse(request.form['schedule'] + '+05:30') error = None if schedule < datetime.datetime.now(pytz.timezone('Asia/Kolkata')): error = 'You can not schedule a message in past' if error: flash(error) job = scheduler.get_job(id) message = MessageModel.find_by_id(_id=id, group_id=group_id) if job and message: schedule_msg(request.form['message'], schedule, group_id, job) message.name = request.form['name'] message.message = request.form['message'] message.schedule = request.form['schedule'] + '+05:30' message.save_to_db() return redirect(url_for('dashboard.index')) return render_template('dashboard/schedules.html')
def post(self): parser = reqparse.RequestParser() parser.add_argument('message_id', type=int, required=True, help='This field is required!') parser.add_argument('application_id', type=int, required=True, help='This field is required!') parser.add_argument('session_id', type=int, required=True, help='This field is required!') parser.add_argument('participants', type=str, required=True, help='This field is required!') parser.add_argument('content', type=str, required=True, help='This field is required!') data_payload = parser.parse_args() if MessageModel.find_by_message_id(data_payload['message_id']): return {'message': 'Message with the same id already exists in database!'}, 400 else: MessageModel.insert_into_table(data_payload['message_id'], data_payload['application_id'], data_payload['session_id'], data_payload['participants'], data_payload['content']) return {'message': 'Message successfully added to the database!'}, 200
def add_schedule(): """ Schedule a message for a group """ if request.method == 'GET': groups = list(map(lambda x: x.json(), GroupModel.query.all())) if len(groups) == 0: flash( "It seems you have not added the @ConsumerSurveyorBot to any group of any channel. Please, add the the bot to any group to schedule the message for the same." ) return redirect(url_for('dashboard.index')) return render_template('dashboard/add_schedule.html', groups=groups) if request.method == 'POST': error = None schedule = parse(request.form['schedule'] + '+05:30') if schedule < datetime.datetime.now(pytz.timezone('Asia/Kolkata')): error = 'You can not schedule a message in past' if error is not None: flash(error) else: print(request.form) job = schedule_msg(request.form['message'], schedule, request.form['group_id']) message = MessageModel(job.id, request.form['name'], request.form['message'], request.form['schedule'] + '+05:30', request.form['group_id']) message.save_to_db() return redirect(url_for('dashboard.index')) return render_template('dashboard/add_schedule.html')
def post(self): user = current_identity request_data = Message.parser.parse_args() message = MessageModel(user.id, **request_data) try: message.save_to_db() except: return {"message": "Internal error occurred."}, 500 return message.json(), 201
def post(self): data = _message_parser.parse_args() data['sender'] = UserModel.find_by_id(get_jwt_identity()).username if UserModel.find_by_username(data['receiver']) is None: return {"error": f"The user {data['receiver']} does not exist."} message = MessageModel(data['sender'], data['receiver'], data['message'], data['subject']) message.save_to_db() return message.json()
def post(self): data = Message.parser.parse_args() messageing = MessageModel(**data) try: messageing.save_to_db() except: return {"message": "An error occurred inserting the message."}, 500 return messageing.json(), 201
def delete(self): args=reqparse.request.args if args: if 'application_id' in args: messages = MessageModel.delete_by_app_id(args['application_id']) elif 'session_id' in args: messages = MessageModel.delete_by_session_id(args['session_id']) else: return {'Not Found': 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again'}, 404 return {'message': 'Messages was successfully deleted from database!'} ,200 return {'Not Found': 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again'}, 404
def get(self): messages=[] args=reqparse.request.args if args: if 'application_id' in args: messages= MessageModel.find_by_app_id(args['application_id']) elif 'session_id' in args: messages = MessageModel.find_by_session_id(args['session_id']) else: return {'method not allowed': 'this url is not exists'}, 404 else: messages = MessageModel.find_all() if messages: return {'message': [message.json() for message in messages]}, 200 return {'message': 'No messages found!'}, 404
def post(self, team_id): # Set data for the message before it gets placed into the database data = Message.parser.parse_args() created_at = time.time() created_by_user = current_identity.username msg_to_save = MessageModel(self.random_id(13), data['message'], data['team_id'], created_at, created_by_user) try: msg_to_save.save_to_db() except Exception as e: print e return {"message": "An error occurred inserting the message."}, 500 #Will desplay message return msg_to_save.json(), 201
def post(self): args = self.reqparse.parse_args() hoge = MessageModel(args.sentence, args.thread_id, args.sender_id) db.session.add(hoge) db.session.commit() res = MessageSchema().dump(hoge).data return res, 201
def get(self, team_id): #Get messages based on team_id messages = MessageModel.find_by_id(team_id) if messages.first(): return {'messages': list(map(lambda x: x.json(), messages))} return {'message': 'No messages found'}, 404
def post(self): data = self.parser.parse_args() # since put it will update regardless # TODO delete if MessageModel.search_for_message(**data): return {'message': "A message like this already exists."}, 400 message = MessageModel(**data) try: message.save_to_db() except Exception as e: return { "message": "An error occurred while saving the item.", "error": "{}".format(e) }, 500 return redirect(url_for("home"))
def delete(self, message_id): user = current_identity message = MessageModel.find_message_by_id(message_id) from_sent = request.args.get('sent') if message: message.delete_from_db(user, from_sent) return {'message': 'Message deleted'}
def create(self, data): sender = SenderModel.first_or_create(id_sender=data["sender_id"]) message = MessageModel.first_or_create( id_sender=data["sender_id"], id_message=data["message_id"], time=f'{data["time"]}', text=data["message_text"], )
def delete(self, message_id): message = MessageModel.find_by_id(message_id) if message: if message.sender == UserModel.find_by_id( get_jwt_identity()).username: message.delete_from_db() return {"info": "Message deleted!"} return {"error": "Message cannot be found in your sent messages"}
def get(self): id = request.args.get('id', None) user_id = request.args.get('user_id', None) sender_id = request.args.get('user_id', None) data = None if id: data = MessageModel.find_by_id(id) elif user_id: data = MessageModel.find_by_user_id(user_id) else: data = MessageModel.find_by_sender_id(sender_id) if data: if id is None: return {'messages': list(map(lambda x: x.json(), data))}, 200 return data.json() return {'message': 'message not found'}, 404
def post(self): parser = reqparse.RequestParser() parser.add_argument(consts.RECEIVER_ID, type=str, required=True, help="This field cannot be blank.") parser.add_argument(consts.CONTENT, type=str, required=True, help="This field cannot be blank.") data = parser.parse_args() message = MessageModel(get_jwt_identity(), data[consts.RECEIVER_ID], data[consts.CONTENT], datetime.utcnow()) message.save_to_db() return message.json(), 201
def delete(self, name): channel = ChannelModel.find_by_name(name) if channel is not None: messages = MessageModel.find_msgs_by_channel_id(channel.channel_id) if messages is not None: for message in messages: message.delete_from_db() channel.delete_from_db() return {'message': 'Channel deleted'}, 201 return {'message': "An channel not found"}, 404
def delete(): message = MessageModel.find_by_id(_id=request.form['id'], group_id=request.form['group_id']) job = scheduler.get_job(request.form['id']) if message and job: try: delete_schedule(job) # message.delete_from_db() this should be automatically handled by the trigger on apschedule_jobs table return redirect(url_for('dashboard.index')) except: flash('Unable to delete the message') flash('No scheduled message found for id {}'.format(request.form['id']))
def get(self, _to): messages = MessageModel.find_all(_to) counter = Counter.find_counter(_to) count = 0 if counter is not None: count = counter.count all = [] if messages: # TODO: FIX THIS TO SEND DATE TIME all = [m.json() for m in messages] return {'messages': all, 'count': count}, 200
def post(self, channel_name): channel_id = ChannelModel.find_id_by_name(channel_name) if channel_id: random_data = randomData() message_id = hashData(str(random_data)) if MessageModel.find_msg_by_channel_id_msg_id( channel_id, message_id): return {'message': 'Bad message id'}, 400 data = Message.parser.parse_args() date_now = datetime.utcnow() user_id = get_jwt_identity() user = UserModel.find_by_id(user_id) print(user.username) message = MessageModel(message_id, channel_id, data['content'], date_now, user.username, UserModel.get_avatar(user.username)) message.save_to_db() return message.json(), 201 else: return {'message': 'Channel not exist.'}, 404
def delete(self, _to): data = self.parser.parse_args() message = MessageModel.search_for_message(_to=_to, **data) if not message: return {'message': "The message does not exist"}, 404 try: message.delete_from_db() except: return ({ "message": "An error occurred while saving the item to the database." }, 500) return {"message": "Item Deleted"}, 200
def delete(self, channel_name, message_id): #claims = get_jwt_claims() #if not claims['is_admin']: # return {'message': 'Admin privilege required.'}, 401 channel_id = ChannelModel.find_id_by_name(channel_name) if channel_id: message = MessageModel.find_msg_by_channel_id_msg_id( channel_id, message_id) if message: message.delete_from_db() return {'message': 'Message was deleted.'}, 201 else: return {'message': 'Message not found.'}, 404
def get(self): parser = reqparse.RequestParser() parser.add_argument(consts.SENDER_ID, type=str, required=True, help="This field cannot be blank.") parser.add_argument(consts.RECEIVER_ID, type=str, required=True, help="This field cannot be blank.") data = parser.parse_args() messages = MessageModel.get_chat_messages(data[consts.SENDER_ID], data[consts.RECEIVER_ID]) messages_json = [message.json() for message in messages] return sorted(messages_json, key=lambda x: x[consts.MESSAGE_ID])
def get(self): people = PeopleModel.find_all() people = [person.person for person in people] messages = MessageModel.find_all() headers = {'Content-Type': 'text/html'} matrices = DrawingModel.find_all() for i in matrices: print(i.json()) return make_response(render_template('home.html', people=people, messages=messages, title="DistancePi", matrices=DrawingModel.find_all() ), 200, headers )
def post(self): data = request.get_json() messages = MessageModel.get_messages_by_session_id(data['session_id']) ui_id = str(data['user_id']) + '_' + str(data['image_id']) image_emotion_dict = Score.get_image_emotion_dict() try: image_emotion = image_emotion_dict[ui_id] except: print("doesn't have corresponding image") image_emotion = '中性' user_id = Score.register_userid() #print(user_id.encode(encoding = 'utf-8')) [d_total_result, d_length_result] = Score.parse_txt(messages, user_id) d_analyzed_result = Score.analyze_txt(d_total_result, d_length_result) v_std = np.load('v_std27.npy') v_diary = Score.vectorize(d_analyzed_result, image_emotion) final_result = Score.grade(v_diary, v_std) emotion_score = np.sum(final_result).ravel() return {'score': emotion_score[0]}
def post(self, name): if MessageModel.find_by_name(name): return { 'message': "An item with name '{}' already exists.".format(name) }, 400 data = Message.parser.parse_args() message = MessageModel(name, data['avatar'], data['date'], data['header'], data['content']) try: message.save_to_db() except: return {"message": "An error occurred inserting the item."}, 500 return message.json(), 201
def get(self): return { "unread_messages": MessageModel.unread_messages( UserModel.find_by_id(get_jwt_identity()).username) }
def get(self): message = MessageModel.read_message( UserModel.find_by_id(get_jwt_identity()).username) return message
def get(self): return { "sent_messages": MessageModel.inbox_messages( UserModel.find_by_id(get_jwt_identity()).username) }