PromptBase
PromptBase SelectGet Select
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
Chat - (gpt-6-luna)
Token size
920
Example input
[PROJECT IDEA]: A command-line habit tracker [LANGUAGE OR STACK]: Python 3.12, standard library only [SKILL LEVEL]: Beginner [MUST-HAVE FEATURES]: Add and remove habits, mark a habit done for today, show current and longest streak per habit, save data in a JSON file [WHERE IT WILL RUN]: A terminal on Windows or macOS
Example output
# **STAGE 1: ASSUMPTIONS AND SCOPE** ## **Assumptions** - **Project:** A simple, local command-line habit tracker. - **Language:** Python 3.12. - **Dependencies:** Python standard library only. No external packages. - **Skill level:** Beginner; commands and code will be explained clearly. - **Environment:** Windows 10/11 (PowerShell) or macOS (Terminal). - **Storage:** A local JSON file called `habits.json`, created automatically when the app first runs. - **Dates:** Habits use the computer's local date. - **Streaks:** A streak is consecutive calendar days on which a habit was completed. Completing a habit today extends a streak; missing a day resets it. - **Daily completion:** Each habit can be marked complete at most once per day. - **Deletion:** Removing a habit deletes its associated history permanently from the local tracker. ## **Scope** Included: - Add a habit. - List all habits. - Remove a habit. - Mark a habit completed today. - View today's completion status. - View current streak and longest streak. - Persist data between sessions in JSON. - Validate input and handle corrupted data files. - Automated unit tests. Deliberately excluded: - User accounts or login. - Cloud synchronization. - Reminders and notifications. - Habit categories or scheduling. - Graphical interface. - Weekly/monthly analytics. - Backup and restore functionality. # **STAGE 2: SPEC** ## **User stories** 1. As a user, I can add a habit with a name so I can track it. 2. As a user, I can see my habits and whether I completed them today. 3. As a user, I can mark a habit done today without accidentally completing it twice. 4. As a user, I can see my current streak and longest streak. 5. As a user, I can remove habits I no longer want to track. 6. As a user, I can close the application and reopen it without losing my data. ## **Data handled** Each habit stores: | Field | Type | Purpose | | ----------------- | --------------- | --------------------------------------- | | `id` | String | Unique identifier | | `name` | String | Habit name | | `completed_dates` | List of strings | Dates completed, formatted `YYYY-MM-DD` | Example stored data: ``` { "habits": [ { "id": "b37d8d...", "name": "Read 10 pages", "completed_dates": [ "2026-11-23", "2026-11-24", "2026-11-25" ] } ] } ``` ## **Inputs and outputs** **Inputs:** CLI commands, habit names, habit IDs, and today's date from the system clock. **Outputs:** Text confirmations, habit lists, streak numbers, error messages, and JSON saved locally. ## **Important edge cases** - Empty habit names. - Duplicate habit names. - Unknown habit ID. - Marking the same habit complete twice. - Empty habit list. - Invalid JSON or corrupted save file. - Missing save file. - Future dates accidentally present in saved data. - Habit names with leading/trailing spaces. # **STAGE 3: ARCHITECTURE** ## **File tree** ``` habit_tracker/ ├── habit_tracker.py ├── test_habit_tracker.py └── habits.json # Created automatically ``` | File | Job | | ----------------------- | ------------------------------------------------------- | | `habit_tracker.py` | Application logic, storage, streak calculation, and CLI | | `test_habit_tracker.py` | Automated tests using `unittest` | | `habits.json` | Persistent local data; generated at runtime | ## **How it works** The application is deliberately kept in one Python file to make it easier to learn and run. The main pieces are: 1. **Storage:** Loads and saves JSON data. 2. **Habit logic:** Adds, removes, and completes habits. 3. **Streak logic:** Calculates consecutive completed days. 4. **CLI:** Reads commands and prints results. The tests import the main file without launching the interactive menu. This lets you test the logic independently. # **STAGE 4: CODE** We'll build an interactive menu rather than requiring you to memorize commands. When you start the program, you'll see options for adding, listing, completing, deleting, and viewing streaks. ## **File 1 — **`habit_tracker.py` Create a file named `habit_tracker.py` and paste the following code into it. ``` """A simple command-line habit tracker for Python 3.12.Data is stored in habits.json in the same directory as this script."""import jsonimport osimport tempfileimport uuidfrom datetime import date, timedeltafrom pathlib import PathDATA_FILE = Path(__file__).with_name("habits.json")def load_data(path=DATA_FILE): """Load habits from JSON, or return an empty list if no file exists.""" if not path.exists(): return {"habits": []} try: with path.open("r", encoding="utf-8") as file: data = json.load(file) except json.JSONDecodeError as exc: raise ValueError( f"The data file contains invalid JSON: {path}" ) from exc if not isinstance(data, dict) or not isinstance(data.get("habits"), list): raise ValueError("The data file has an invalid structure.") # Validate each habit before trusting the stored data. for habit in data["habits"]: ``` # **STAGE 5: TESTS** We'll use Python's built-in `unittest` framework. You don't need to install a testing package. The tests cover: - Adding habits. - Duplicate and blank names. - Completing habits. - Preventing duplicate completions. - Streak calculations. - Removing habits. - Saving and loading JSON. - Invalid JSON. - Unknown habit IDs. ## **File 2 — **`test_habit_tracker.py` Create this file in the same directory. ``` import jsonimport tempfileimport unittestfrom datetime import datefrom pathlib import Pathfrom habit_tracker import ( add_habit, calculate_streaks, find_habit, list_habits, load_data, mark_done, remove_habit, save_data,)class HabitTrackerTests(unittest.TestCase): def setUp(self): self.data = {"habits": []} self.today = date(2026, 11, 25) def test_add_habit(self): habit = add_habit(self.data, " Read books ") self.assertEqual(habit["name"], "Read books") self.assertEqual(habit["completed_dates"], []) self.assertEqual(len(habit["id"]), 8) self.assertEqual(len(self.data["habits"]), 1) def test_reject_blank_habit_name(self): with self.assertRaises(ValueError): add_habit(self.data, " ") ``` ## **Automated test coverage** The tests include more than two failure cases: | Test | Expected result | | ---------------------- | ---------------------- | | Blank name | Rejected | | Duplicate habit | Rejected | | Duplicate completion | Rejected | | Unknown ID | Rejected | | Invalid JSON | Rejected | | Invalid data structure | Rejected | | Missing file | Empty tracker returned | | Future dates | Ignored for streaks | ## **Three manual checks** ### **Check 1 — Add a habit** 1. Start the application. 2. Choose `1`. 3. Enter `Drink water`. Expected output: ``` Added "Drink water" (ID: xxxxxxxx). ``` The ID will be randomly generated. ### **Check 2 — Complete a habit** 1. Choose `2` to list habits. 2. Copy the ID shown for `Drink water`. 3. Choose `3`. 4. Enter the ID. Expected output: ``` "Drink water" marked done for today! ``` If you try it again, you should receive: ``` Error: This habit is already completed today. ``` ### **Check 3 — Persistence** 1. Choose `5` to quit. 2. Run the program again. 3. Choose `2`. Expected result: your habit still exists, and it is marked `Done` for today, with a current streak of `1 days`. # **STAGE 6: RUN IT** ## **1. Create your project folder** ### **Windows (PowerShell)** ``` mkdir habit_tracker cd habit_tracker ``` ### **macOS (Terminal)** ``` mkdir habit_tracker cd habit_tracker ``` Create the two files from Stage 4 inside this folder: - `habit_tracker.py` - `test_habit_tracker.py` ## **2. Check Python is installed** ### **Windows** ``` py -3.12 --version ``` ### **macOS** ``` python3.12 --version ``` Expected output: ``` Python 3.12.x ``` If the command isn't recognized, install Python 3.12 from [the official Python downloads page](https://www.python.org/downloads/?utm_source=chatgpt.com). ## **3. Start the application** ### **Windows** ``` py -3.12 habit_tracker.py ``` ### **macOS** ``` python3.12 habit_tracker.py ``` Expected output: ``` Welcome to Habit Tracker! === HABIT TRACKER === 1. Add a habit 2. List habits 3. Mark habit done today 4. Remove a habit 5. Quit Choose an option (1-5): ``` ## **4. Run the automated tests** Stop the application if it is running, then execute: ### **Windows** ``` py -3.12 -m unittest -v ``` ### **macOS** ``` python3.12 -m unittest -v ``` Expected output (summary): ``` Ran 15 tests in 0.0xxs OK ``` How to tell it's working: You can add a habit, mark it completed, quit, reopen the program, and see that the habit and its completion history remain saved. # **STAGE 7: SELF-REVIEW** I reviewed the implementation as if I were checking a beginner's project before handing it off. I found one actual bug and a few limitations worth knowing. ## **1. Bug: missing-file check** The original code mistakenly checks `path.exists` instead of calling `path.exists()`. Without the parentheses, the missing-file check doesn't actually execute, which causes a failure when the app starts for the first time. **Fix:** In `habit_tracker.py`, inside `load_data()`, replace: ``` if not path.exists: return {"habits": []} ``` With: ``` if not path.exists(): return {"habits": []} ``` This is an important fix. Apply it before running the tests. ## **2. Streak definition could surprise users** Current streak is zero if you miss yesterday and haven't completed today. This is intentional. The longest streak remains historical and is not affected by missed days after that streak ended. ## **3. No backup of your data** If `habits.json` is accidentally deleted, the tracker loses its history. **Mitigation:** Periodically copy `habits.json` to another folder or cloud drive. ## **4. Data is editable** Anyone with access to the computer can modify the JSON file. This is fine for a personal habit tracker, but it is not designed for tamper-resistant records. ## **5. Habit IDs are short** The program uses 8-character IDs. Collision risk is small for a personal tracker, but not impossible. A larger application should use full UUIDs. For this version, none of these limitations requires adding dependencies or expanding the project. # **STAGE 8: NEXT STEPS** Here are five upgrades I'd recommend in order: | Priority | Upgrade | Effort | First step | | -------- | ---------------------- | ------ | ------------------------------------------------------------ | | 1 | Habit editing | Small | Add an `edit_habit()` function to rename habits. | | 2 | Weekly summary | Small | Count completions in the last 7 days. | | 3 | Export and backup | Small | Add a command to export JSON or CSV to another location. | | 4 | Habit schedules | Medium | Add a frequency field, such as daily or weekdays only. | | 5 | Visual progress charts | Medium | Display streak history using a text-based calendar or chart. | ## **What you learned by building this** This project introduces several useful real-world Python concepts: - **Functions:** Reusable operations such as `add_habit()` and `mark_done()`. - **Data structures:** Dictionaries and lists for representing habits. - **JSON:** Saving structured data to a file and loading it again. - **Exceptions:** Handling invalid input and corrupted files. - **Dates:** Calculating consecutive calendar days. - **Testing:** Verifying your logic automatically with `unittest`. - **CLI design:** Creating an interactive menu for terminal users. - **Atomic file saving:** Reducing the risk of corrupting your data during a save. The best next upgrade would be the weekly summary, because it builds on the date-handling logic you already have without making the project much more complicated. Not run or tested by me. Run the Stage 5 tests before relying on this code. Want a change? Reply with change: and one request, such as a new feature, a different library, a simpler version or a bug fix.
GPT

Project Builder Complete Code To Tests

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
GPT-6-LUNA
Tested icon
Guide icon
4 examples icon
Free credits icon
Turn a project idea into a small working project in one pass. Enter your idea, language or stack, skill level, must-have features and where it runs. You get assumptions, a short spec, a file tree, complete code for every file, automated tests, run steps, a self-review of risks with fixes, and prioritized next steps. Works across Python, JavaScript, Node and more. Reply with change: and one request to revise. The code is not run by the prompt, so test it.
...more
Added 33 minutes ago
Report
Browse Marketplace