The file_processing.py File This file contains functions that are used for processing the files associated with streaming services. It contains three functions. In all likelihood, you will find this...

The file_processing.py File This file contains functions that are used for processing the files associated with streaming services. It contains three functions. In all likelihood, you will find this to be the most difficult of the files to write. You will probably have to do a fair bit of debugging to get this working correctly. Assignment #4 CS 1026 Summer 2022 6 • Function Name: build_new_service() This function reads a data file containing a streaming service's information. This function should use try/except to ensure that the file it is passed is valid. • Parameter: a data file containing streaming service data. • Return Value: o if the file is found, a StreamingService object built from the data file's information o if the file isn't found, None o How it works: A data file for building the StreamingService object looks like this: NETFLIX PROGRAMS Halt and Catch Fire,Christopher Cantwell and Christopher C. Rogers,Drama,2014 Arrival,Drama,Denis Villeneuve,2016 Us,Horror,Jordan Peele,2018 Matrix; The,Sci-Fi,The Wachowskis,1999 SUBSCRIBERS John,john123,password Farah,f206,abcdef File 1-The netflix.csv Data File 1. First, you will have to instantiate a StreamingService object. 2. The first line of the file is the name of the streaming service. This name will always be in uppercase letters. 3. The second line of the data file will always be PROGRAMS. 4. Everything listed after PROGRAMS and before SUBSCRIBERS will be read as a Program object. So, when you are reading this file, the information on each of these lines should be instantiated as a new Program object and stored in the streaming service's list of programs. 5. Everything after SUBSCRIBERS is a Subscriber object. The information on each of these lines will be instantiated as new Subscriber objects and stored in the streaming service's list of subscribers. Tip: You can use next(reader) (assuming your csv.reader variable is called reader) to move to the next line (similar to using readline() with a .txt file). You may need to use this to avoid PROGRAMS and SUBSCRIBERS being read as data. Assignment #4 CS 1026 Summer 2022 7 • Function Name: update_service() This function reads an update file containing changes to a streaming service's data. This function should use try/except to ensure that the file it is passed is valid and that any entries being updated already exist in the streaming service. • Parameters: o an update file containing streaming service data o a StreamingService object • Return Value: o if the file is found, a StreamingService object built from the data file's information o if the file isn't found, None o if an entry that requires an update isn't already present in the streaming service's lists, None o How it works: An update file looks like this: NETFLIX PROGRAMS Halt and Catch Fire,Christopher Cantwell and Christopher C. Rogers,Drama,2014 Arrival,Drama,Denis Villeneuve,2016 ^,Us,,,2019 -The Matrix,Science Fiction,The Wachowskis,1999 +,Squid Game,Thriller,Hwang Dong-hyuk,2021 +,Dark,Mystery,Baran bo Odar and Jantje Friese,2017 SUBSCRIBERS -,John,john123,password ^,Farah,,abcdefg +,Candice,candy2000,12345 File 2-The update_netflix.csv Data File 1. You can read this file similarly to how you read the data file, but an update file behaves differently (as you can see in Step #6). 2. The first line of the file is the name of streaming service. This name will always be in uppercase letters. 3. The second line of the update file will always be PROGRAMS. 4. Everything listed after PROGRAMS and before SUBSCRIBERS represents a Program object. 5. Everything after SUBSCRIBERS represents a Subscriber object. Assignment #4 CS 1026 Summer 2022 8 6. For both the Program and Subscriber objects, you will see some lines that contain one of these symbols (+, -, ^). What follows are instructions for dealing with lines that contain these symbols: +: this symbol means that the entry on that line is to be added to the appropriate streaming service list. You must instantiate a new Program or Subscriber object (depending on the section of the file that you're in), and then add it to the appropriate streaming service list. -: this symbol means that the entry on that line is to be removed from the appropriate streaming service list. ^: this symbol means that the entry on that line requires an update. Notice that update lines may have entries that aren't entered (as signified by commas with nothing between/after them). These details will already be present in the object being updated, so you will only have to update the sections of information that are provided in the update file, while not overwriting the information already present in that object. For example, if the streaming service contains a Program with the following information: Program(Matrix; The,Sci-Fi,The Wachowskis,1999) and the update file contains the following line: ^,Matrix; The,Action,, then you should update the streaming service's program list so that it contains the following information: Program(Matrix; The,Action,The Wachowskis,1999) IMPORTANT FOR MAKING YOUR LIFE EASIER: The files that your program will be tested with, like the example files provided, will always contain the correct number of Assignment #4 CS 1026 Summer 2022 9 commas. Additionally, the title of a Program object and the name of a Subscriber object will never require an update. Tip: Just as with the previous function, you can use next(reader) to move to the next line (similar to using readline() with a .txt file). You may need to use this to avoid PROGRAMS and SUBSCRIBERS being read as data. Tip #2: This is one of the toughest parts of the assignment, logically speaking, so you'll want to plan this function out rather than just trying to code it immediately. You will likely need to debug it quite a bit, too. • Function Name: write_update() This function writes the updated streaming service to a new file. • Parameters: o the name of the file to write to o a StreamingService object o How it works: The new file looks like this: NETFLIX PROGRAMS Arrival,Drama,Denis Villeneuve,2016 Dark,Mystery,Baran bo Odar and Jantje Friese,2017 Halt and Catch Fire,Christopher Cantwell and Christopher C. Rogers,Drama,2014 Matrix; The,Sci-Fi,The Wachowskis,1999 Squid Game,Thriller,Hwang Dong-hyuk,2021 Us,Horror,Jordan Peele,2019 SUBSCRIBERS Candice,candy2000,12345 Farah,f206,abcdefg File 3-The new_netflix.csv Data File 1. The first line written should be the name of the service in uppercase letters. 2. The next line should be PROGRAMS. 3. The list of Program objects should then be written to the file. Note: these are not the __repr__ versions of a Program object, but each of the object's elements as strings separated by commas. Assignment #4 CS 1026 Summer 2022 10 4. After the programs have been written to the file, the next line should be SUBSCRIBERS. 5. The list of Subscriber objects should then be written to the file. Note: these are not the __repr__ versions of a Subscriber object, but each of the object's elements as strings separated by commas. Hint for #3 and #5: If you make each row a list with the appropriate entries, the CSV writer's writerow() function should do the rest of the work. The main.py File This file contains the main() function that handles running the user's input. It looks like this when run: main.py Assignment #4 CS 1026 Summer 2022 11 1. The program asks the user if they want to update a file. The program accepts Y or y as 'yes' and N or n as 'no'. All other input here is considered invalid, and it should be handled using try/except. (Hint: raise an error if the input is invalid.) If the user chooses 'yes', then they go to Step #2. If the user chooses 'no', then the program exits. 2. The program prompts the user for a filename. The user can enter the name of a data file here, or they can type done to exit the program. You can have the program exit gracefully by using the function exit(0) if the user types done. If the user enters a filename, the program calls the build_new_service() function from file_processing.py. 3. The program prompts the user for the name of the appropriate update file. The user can enter the name of an update file here, or they can type done to exit the program. If the user enters an update filename, the program calls the update_service() function from file_processing.py. The result of this call should then be sorted so that the updated file will contain sorted lists of programs and subscribers. 4. The program prompts the user for a new filename. The user can enter the name of a file to write to, or they can type done to exit the program. If the user enters a new filename, the program calls the write_update() function from file_processing.py. 5. All the above steps are then repeated. The user is prompted for Y/N again, and they can build another streaming service file. At any point, they can enter done to exit. 6. When the user exits, any files they have created should appear in the current working directory. Phew! You made it! It seems like a lot, and it certainly is a significant amount of programming, but most of the heavy work is in file_processing.py. Assignment #4 CS 1026 Summer 2022 12 Non-Functional Requirements/Specifications 1. Include brief comments in your code identifying yourself (i.e., include your student number in a comment at the beginning of your program) and describing what the program does. Include docstrings describing what each function does. Place these comments in the appropriate places in the program. 2. Assignments are to be done individually and must be your own work. Software may be used to detect academic dishonesty (cheating). You may, of course, talk about your code with others and give each other tips, but you cannot share code with each other (this includes showing someone your code on a screen). 3. Use Python coding conventions and good programming techniques. Examples include: § meaningful variable names; § conventions for naming variables and classes; § readability; and § indentation. 4. Submit the program.py, subscriber.py, streaming_service.py, file_processing.py, and main.py files to Gradescope. The autograder will be available beginning Tuesday, June 14 at 5pm. 5. Make sure to use Python 3.8 or later for the interpreter. If you don’t use one of these versions of Python, the tests the autograder runs may fail, causing you to lose
Jun 18, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here