def send_message(user_from, user_to_username, msg_text): user_to = User.load_user_by_name(user_to_username) if user_to: message = Message() message.from_id = user_from.id message.to_id = user_to.id message.msg_text = msg_text return message.save_to_db() raise ValueError(f"No user '{user_to_username}' in the database.")
for message in messages: print( f"From:{User.load_user_by_id(cur, message.from_id).username}\n Date: {message.creation_date}\n Message: {message.text}") else: print("Password incorrect") elif args.send: if args.username is not None and args.password is not None: user = User.load_user_by_email(cur, args.username) hashed = user.hashed_password if check_password(args.password, hashed): if args.to is not None: recipient = User.load_user_by_email(cur, args.to) if recipient is not None: if args.send is not None: new_message = Message() new_message.to_id = recipient.id new_message.from_id = user.id new_message.text = args.send new_message.creation_date = datetime.now() new_message.save_to_db(cur) print(f"You send a message to {recipient.username}") else: print("Please enter a message") else: print("There is no user with this mail") else: print("Password incorrect") else: parser.print_help()