Answered step by step
Verified Expert Solution
Question
1 Approved Answer
New Method Create a method called parse ( ) . It must accept an argument that contains an integer value representing the month ( 1
New Method
Create a method called parse It must accept an argument that contains an integer value representing the month Hint: Command line arguments are strings by default!
In this method, use a list comprehension to filter ONLY the log entries whose eventtime matches the month of the argument.
Print the number of log entries from this month to the screen.
New Argument
To implement this action, you will need to accept a new NONREQUIRED command line argument month, or m
Implement the New Method
Update your program to allow the user to provide the value parse to the action argument.
If the user chooses this action, verify that they have passed in a valid month it will be an integer from
If the month is valid, call the parse method and pass the value of the month argument.
View the Result
The command
python index.py filename firewalllogscsv action parse month
Should result in a print statement that says the following the number will be different based on the data:
log entries were recorded in month
Export Data up to points
If a user correctly executes the command to parse a specific month of data, also add the functionality that writes ONLY the events that occurred in that month to a new CSV file.
For example, if the user chose as their month, your program should produce a CSV file named logscsv
Hints and Tips
You can use the csvDictWriter module to create a CSV file
Remember that the imported data in your program is stored as a list of objects of class LogEntry. You will need to convert the filtered objects into dictionaries before using DictWriter.
Your CSV file should contain a header row that labels all the columns in the remaining rows of your CSV file it should have the same structure as the firewalllogssample.csv file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started