When the covid-19 situation arose in early 2020 your small teamof developers quickly found out how much questions you used to askeach other in person. Now that you all work from home most of thetime you have resorted to using online chat instead. But this hasresulted in that you all have to go back and read endless chat logswhen you forget what you agreed on earlier.
To remedy this problem, you have decided to write a small scriptthat reads a log file and then allow you to search for all messagessent by one user. To make the script a bit more versatile you havedecided that the path to the log file shall be sent as a commandline argument to the script. As everyone in the team is a bitsloppy when typing, the script needs to have error handling thatclearly informs the user in case the specified path to the log filedoes not exist. The format of the error message can be seen in thisexample:
Error: The file ‘/Users/nna/messages.txt’ could not be found.
The script shall have a main function, a function for readingfrom the log file, and a function for formatting and displaying amessage on the screen. There are some rules for how thefile-reading function and the display function shall work:
read_file(filename)
Shall read the file specified by the parameter filename and createa list of tuples that is then returned. Each tuple shall consist ofa name and a message. In the file each message takes up two rows,where the first row contains the senders name, and the second rowcontains the text of the message. Each log file can of coursecontain many messages sent by many different persons.
display_entry(name, message)
Shall use the two parameters to display a formatted output on thescreen. The output shall follow this format:
[name] --> message
All other functionality needed in the script shall be added inthe main function, this includes but is not limited to asking whatname to search the log file for.