Please use python.
My current codes are:
import datetime
import os.path
def send_message(sender, recipient, message):
d = datetime.datetime.now()
# change the format of the time to what we want
new_datetime = str(d)[:-7].replace(“-“, “/”)
new_message = sender + “|” + new_datetime + “|” + message +
“n”
if os.path.isfile(“messages/” + recipient + “.txt”):
fp = open(“messages/” + recipient + “.txt”, “a”)
data = fp.write(new_message)
else:
fp = open(“messages/” + recipient + “.txt”, “w+”)
welcome = fp.write(“Welcome to your account!” + “n”)
data = fp.write(new_message)
fp.close()
# TESTER CODE
send_message(‘pikachu’, ‘charmander’, ‘Hey there!’)
send_message(‘charmander’, ‘pikachu’, ‘Good to see you!’)
send_message(‘pikachu’, ‘charmander’, ‘You too, ttyl’)
There will be two files created: pikachu.txt and
charmander.txt
What I need to do is to create another function that prints all
messages sent to the username in question.
The output should be something like:
In the file named ‘charmander.txt’:
pikachu|11/14/2020 13:37:15|Hey there! pikachu|11/14/2020 13:37:15|You too, ttyl
Messages should be generated like this:
Message #1 received from pikachu Time: 11/14/2020 13:37:15 Hey there!
Message #2 received from pikachu Time: 11/14/2020 13:37:15 You too, ttyl
Please do not use the split function.
Thank you!