I made this (link to python file on dropbox). It won't run in the trinket.io page, but you could look at the code if you were so inclined. The (minimum) design specs are in the red text surrounded by ''' (i.e. the long comments at beginning and end)
"It" it is a basic budget app. You interact with it via command line (as with everything else I've made in python so far). It's only 217 lines, and half of those empty space, but it's some of the densest code I've written. It's mostly an exercise in memory management using dictionaries and data i/o using csv files.
Features:
1. Asks user for item/cost/recurring and stores that info in hash, using a counter variable as the key.
2. Maintains a speed-lookup dictionary with name: key pairs (where name is the name of the item...important since some app functions require lookup by item name and this allows quick lookup of where an item is stored.
3. All functions (save for a few specialized uses) take a state variable as their only argument. The state variable contains the dictionary of items in the budget, the counter variable for generating keys, the speed lookup dictionary, the file name that is the source of any data, or the destination of data to be written.
4. Instead of a simple while loop that ends when the q(for quit) key is pressed, q calls a function that saves the current budget inventory in a "temp.csv" file and uses "raise SystemExit()" to terminate the program. I remember losing an hour of work once when using a crappy old Pascal program to process data, and I didn't quit properly.
5. A dictionary for switching among functions based on user input. The switch uses dict.get() so that I can handle edge cases with an "error" function that tells the user to re-enter their choice.
6. a file import function that opens a csv and imports it into the dictionary used in the script. The script will parse the key values written in the source file, and set the state counter to the max key value among the imported data. (The "add new item" function increments the counter before an item is actually added).
7. Item delete, with the user being able to type in the item name. Again, a get function provides some edge case handling.
Future:
1. a user input checking/cleaning module
2. differentiate between input/output files
3. dynamic column names/dictionary keys depending on user input and/or csv contents
4. delete column based on user input
5. forecasting expenses.
Not bad for one day's work at this stage.
No comments:
Post a Comment