The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a command-line gratitude journal

Here’s a simple command-line gratitude journal written in Python. It allows users to add, view, and search gratitude entries using a basic terminal interface and stores data in a local file.


💡 Features:

  • Add new gratitude entries with timestamps

  • View all past entries

  • Search entries by keyword

  • Save data in a text file (gratitude_journal.txt)


✅ Code: gratitude_journal.py

python
import os import datetime JOURNAL_FILE = "gratitude_journal.txt" def add_entry(): entry = input("What are you grateful for today?n> ").strip() if not entry: print("Entry cannot be empty.") return timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") with open(JOURNAL_FILE, "a", encoding="utf-8") as f: f.write(f"[{timestamp}] {entry}n") print("✅ Entry saved!n") def view_entries(): if not os.path.exists(JOURNAL_FILE): print("No entries found.n") return with open(JOURNAL_FILE, "r", encoding="utf-8") as f: entries = f.readlines() if not entries: print("Journal is empty.n") return print("n📝 Gratitude Journal:n") for entry in entries: print(entry.strip()) print() def search_entries(): keyword = input("Enter keyword to search: ").strip().lower() if not keyword: print("Keyword cannot be empty.n") return with open(JOURNAL_FILE, "r", encoding="utf-8") as f: entries = [line.strip() for line in f if keyword in line.lower()] if not entries: print("No matching entries found.n") else: print(f"n🔍 Found {len(entries)} entries:n") for entry in entries: print(entry) print() def menu(): while True: print("==== Gratitude Journal ====") print("1. Add Entry") print("2. View Entries") print("3. Search Entries") print("4. Exit") choice = input("Choose an option (1-4): ").strip() if choice == "1": add_entry() elif choice == "2": view_entries() elif choice == "3": search_entries() elif choice == "4": print("Goodbye! 👋") break else: print("Invalid choice. Please try again.n") if __name__ == "__main__": menu()

▶️ How to Use:

  1. Save the code in a file called gratitude_journal.py.

  2. Open terminal/command prompt.

  3. Run it using:

    bash
    python gratitude_journal.py
  4. Follow the menu to add or read entries.


Let me know if you want a version with encryption, cloud sync, or a GUI.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About