Question

In: Computer Science

When the covid-19 situation arose in early 2020 your small team of developers quickly found out...

When the covid-19 situation arose in early 2020 your small team of developers quickly found out how much questions you used to ask each other in person. Now that you all work from home most of the time you have resorted to using online chat instead. But this has resulted in that you all have to go back and read endless chat logs when you forget what you agreed on earlier.

To remedy this problem, you have decided to write a small script that reads a log file and then allow you to search for all messages sent by one user. To make the script a bit more versatile you have decided that the path to the log file shall be sent as a command line argument to the script. As everyone in the team is a bit sloppy when typing, the script needs to have error handling that clearly informs the user in case the specified path to the log file does not exist. The format of the error message can be seen in this example:

Error: The file ‘/Users/nna/messages.txt’ could not be found.

The script shall have a main function, a function for reading from the log file, and a function for formatting and displaying a message on the screen. There are some rules for how the file-reading function and the display function shall work:

read_file(filename)
Shall read the file specified by the parameter filename and create a list of tuples that is then returned. Each tuple shall consist of a name and a message. In the file each message takes up two rows, where the first row contains the senders name, and the second row contains the text of the message. Each log file can of course contain many messages sent by many different persons.

display_entry(name, message)
Shall use the two parameters to display a formatted output on the screen. The output shall follow this format:
[name] --> message

All other functionality needed in the script shall be added in the main function, this includes but is not limited to asking what name to search the log file for.

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import sys
import os


def read_file(filename):
    messages = []
    f = open(filename, 'r')
    lines = f.readlines()
    temp_list = [0, 1]
    for i in range(len(lines)):
        if(i % 2 == 0):
            temp_list[0] = lines[i].strip().lower()
        else:
            temp_list[1] = lines[i].strip()
            messages.append(tuple(temp_list))
    return messages


def display_entry(name, message):
    print(name+"-->"+message)


try:
    messages = read_file(sys.argv[1])
    name = input("Enter the name to search:").lower()
    count = 0
    print("Messages are:")
    for i in messages:
        if(i[0] == name):
            display_entry(*i)
            count += 1
    if(count == 0):
        print("There are no messages with entered name in the logs")
except:
    print("File error!!")

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

message.txt

Barry
Hello im a frontend developer
Harry 
Hello im a backend developer
Barry
Hello team today a fixed a small glitch in the front end
Sally
Hello im the system administrator
Ben
Hello im server administrator
Barry
our server admin our companies web server is down please check it out
Harry
hello system admin please change my system password
Sally
Hey i changed your password and sent you a message please check it out.
Nora
Hello im sales manager
Nora 
hello system admin can you create an account for me in the system
Sally
Ok Nora wait i will create you an account

Related Solutions

You manage a small team of developers that works on internal projects for your company. You...
You manage a small team of developers that works on internal projects for your company. You have two potential projects your team has the opportunity to work on. For the first project (Project A), your company has provided you an initial set of application features asked you to develop a cost estimate for the application. Below is some standard data on the team: Project A Description Number Number of team members 5 Developer Cost per person per day $80 Work...
Supply and Demand: In early 2020 the COVID-19 pandemic swept across the nation and world. In...
Supply and Demand: In early 2020 the COVID-19 pandemic swept across the nation and world. In response, many workers moved from in-person working to remote working. Webcams in particular showed an increase in the amount sold, especially the most well-known and trusted brands. a. Most webcams are produced in China. The US is currently in a trade war with the Chinese which effectively causes additional costs on the production of Chinese goods through tariffs (i.e., taxes). Suppose after the next...
create your own Balanced Scorecard as a city official trying to improve COVID-19 situation. Make sure...
create your own Balanced Scorecard as a city official trying to improve COVID-19 situation. Make sure to have vision, mission, strategic objectives, strategy map, measures, targets and actions. The BSC must include some IT objectives or actions. You can you power point to create the BSC.
COVID-19 continues to cause major disruptions in late 2020. Write any post of your choosing that...
COVID-19 continues to cause major disruptions in late 2020. Write any post of your choosing that discusses COVID-19 from a pharmacological standpoint. Your post MUST contain information that we have learned about antivirals and/or vaccines in this unit to receive any credit. If you so desire, you may use additional sources as references, but please be on high alert - there is a LOT of fake news about COVID-19, so you MUST use trusted sources (such as CDC, WHO, Wall...
(1) You freeze a bottle of milk quickly in your freezer so it becomes a solid. When you take it out and let the solid thaw, how does the liquid tastes like?
  (1) You freeze a bottle of milk quickly in your freezer so it becomes a solid. When you take it out and let the solid thaw, how does the liquid tastes like? (2) What is the concentration of milk in the liquid when it first thaw? (3) How does the milk concentration change in the solid as it melts continuously and you drink the liquid? (4) Could you obtain pure water from your milk? How? (5) Since a lot...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT