In this guide you will clone or download the Corner Grocer source files, create a small grocery input file, and run both the file-based and database-backed versions of the application from your terminal. By the end you will have a working frequency tracker, a populated SQLite database, and a clear picture of what each menu option does.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/corner-grocer/llms.txt
Use this file to discover all available pages before exploring further.
Download the source files
Grab the four Python files from the
downloads/ directory of the repository and place them all in the same working directory on your machine:corner_grocer.py and corner_grocer_main.py are the two entry points. Both import grocery_utils; corner_grocer_main.py additionally imports db_handler. Keeping all four files together means Python can resolve every import without any extra configuration.Create an input file
Create a plain-text file called Items are normalized to lowercase when they are read, so you can mix capitalisation freely. Blank lines are ignored.For the file-based version (
grocery_input.txt in the same directory. Add one item per line — the file below uses real items from the included sample:corner_grocer.py), the default input filename is grocery_frequency_input.txt. You can either rename your file or edit the INPUT_FILE constant near the bottom of corner_grocer.py.Run the file-based version
From your project directory, run:Corner Grocer reads Menu input is validated — entering a letter or a number outside 1–7 prints an error message and re-displays the prompt without crashing.
grocery_frequency_input.txt, builds the frequency map in memory, and drops you into a 7-option interactive menu:Run the database-backed version
For persistent storage, run the second entry point:On first launch, Because counts are stored in SQLite, running the program a second time with the same input file accumulates the new counts rather than resetting them.
db_handler.py automatically creates grocery.db in the working directory and sets up the grocery_frequency table. The program then reads grocery_input.txt, populates the database, and opens a 9-option menu:What to expect
The table below covers every menu option across both entry points. Options 1–6 behave identically in both programs; options 7–9 are exclusive tocorner_grocer_main.py.
| Option | Label | Description |
|---|---|---|
| 1 | Look up item frequency | Prompts for an item name and prints how many times it appears in the purchase log. Returns 0 for unknown items. |
| 2 | Print all items and frequencies | Displays every tracked item and its count, sorted alphabetically by get_all_frequencies() or print_all_frequencies(). |
| 3 | Print frequency histogram | Renders a text bar chart — one * per purchase — for every item, sorted alphabetically. |
| 4 | Sort items alphabetically (A–Z) | Calls grocery_utils.sort_alpha() to print all items in A–Z order with their counts. |
| 5 | Sort items by frequency (high → low) | Calls grocery_utils.sort_by_freq() to rank items from most to least purchased. In the DB version, ties are broken alphabetically by the SQL ORDER BY. |
| 6 | Search for a specific item | Calls grocery_utils.search_item(), which normalizes the query and either prints the count or Item not found. |
| 7 (DB only) | Save frequency list to file | Writes all item names and counts to frequency_list.dat as item count pairs, one per line. |
| 8 (DB only) | Save histogram to file | Writes the asterisk histogram (sorted by frequency descending) to frequency_histogram.dat. |
| 7 (file) / 9 (DB) | Exit program | Prints Goodbye!, exits the menu loop, and — in the DB version — closes the SQLite connection cleanly. |