For this assignment, you are going to pretend that you are writing an application that uses JSON to store configuration data in it.
First, you are going to start by writing a JSON file called ("basic_config.json") that stores the following variables and their associated values:
1. Safe Mode - "On"
2. Memory - "32MB"
3. Error Log - "logs/errors.log"
Your program is going to load all of these values up on startup, display them just like I have them above, and then give the user the option to either modify an existing value or add new ones.
Use your program to add the following configuration options (note that you are not limited to just these - I am asking you to add them using your program):
Allow File Uploads - "Yes"
Use Caching - "Yes"
Caching File - "cache/filecache.cache"
Mail Host - "mail.apphost.com"
Also, give the user the option to either save their changes or discard them. If the user chooses to accept the changes, the new configuration will be saved as config_override.json. Under no circumstances should basic_config.json ever be overwritten.
On subsequent program runs, in order to make this work properly, you are going to need to implement a check to see if config_override.json exists before loading the information in basic_config.json. In other words, once basic_config.json has been overridden, you should always load config_override.json from that point on to make your changes and adjustments. When you save back, you must have a means in place to backup your old file. You do not need to have functionality in place to have your applications load or restore data from old backups.
Users may modify the value of any setting they wish, but they can only delete configurations for items not in the original configuration such as:
Allow File Uploads - "Yes"
Use Caching - "Yes"
Caching File - "cache/filecache.cache"
Mail Host - "mail.apphost.com"
In other words, the keys contained in the basic_config.json file are all required. You must add logic and decide the best way to delete items the user wishes to remove.
Finally, you will create functions to (minimally - you can and probably should write more functions than the ones listed below) handle the following tasks:
Please note that you must organize your functions into modules and produce documentation (using Pydoc) for your work using the principles discussed earlier in the class. You must also include exception handling in your code according to the principles previously discussed and explored in more detail this week.
Problem 1:
Create a text file that has at least 5 of your favorite movies in it, each on its own line. Open the file in Python and append the phrase, "is a movie I like" to each line. Write out each your new lines to a single new output file.
Problem 2:
Write a while loop that prompts a user for what they'd like for dinner over the course of the next week. After they provide you with a selection, add it to a file called "dinner_menu.txt". Make sure each entry appears on its own line and provide a way for the user to exit the loop.
Problem 3:
Modify your code in Problem 1 to fail silently if either the input file or output file was not found.
Problem 4:
Write a program that loads data from a file called my_car.json. If the file doesn't exist or there is no data in it, prompt the user to enter the model of the car they drive and store it in my_car.json using json.dump().
If the file exists and there's data in it, print out the contents of the file using json.load(). Then, ask the user if they'd like to change the model of the car they drive. If they would, ask the user for the new car model information and store it in my_car.json using json.dump().