22 – Real-World Python Projects – Personal Diary / Journal App

๐ŸŽฏ Project Objective

To create a secure and organized digital diary application that allows users to write, view, edit, search, and save personal notes with date and time stamps โ€” optionally password-protected.


๐Ÿงฉ 1. Project Overview

A Personal Diary App helps users record daily thoughts, plans, and experiences.
This project combines file handling, datetime, encryption, and GUI (optional) for a professional journaling experience.

โœจ Real-World Uses:

  • Maintain a digital journal securely
  • Track daily moods or productivity
  • Store study or work reflections
  • Create private notes with password protection

โš™๏ธ 2. Required Modules

These modules will auto-install if missing.

import os
import datetime
import getpass

# Auto-install modules if missing
try:
    from cryptography.fernet import Fernet
except ModuleNotFoundError:
    import subprocess
    subprocess.check_call(["pip", "install", "cryptography"])
    from cryptography.fernet import Fernet

๐Ÿง  3. Generate Encryption Key

To secure diary entries, weโ€™ll use encryption.

def generate_key():
    """Generate and store a key for encryption"""
    if not os.path.exists("secret.key"):
        key = Fernet.generate_key()
        with open("secret.key", "wb") as key_file:
            key_file.write(key)
    else:
        with open("secret.key", "rb") as key_file:
            key = key_file.read()
    return Fernet(key)

๐Ÿงพ 4. Add New Diary Entry

def add_entry():
    fernet = generate_key()
    entry = input("Write your diary entry:\n")
    date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    encrypted_entry = fernet.encrypt(entry.encode())

    with open("diary.txt", "ab") as file:
        file.write(f"\n[{date}] ".encode() + encrypted_entry + b"\n")
    print("โœ… Entry saved successfully!")

๐Ÿ“– 5. View Diary Entries

def view_entries():
    fernet = generate_key()
    if not os.path.exists("diary.txt"):
        print("No diary entries found.")
        return

    with open("diary.txt", "rb") as file:
        lines = file.readlines()

    print("\n๐Ÿ““ Your Diary Entries:\n")
    for line in lines:
        if line.strip():
            try:
                if line.startswith(b"["):
                    timestamp = line.decode(errors="ignore").split("]")[0] + "]"
                    print(timestamp)
                else:
                    print(fernet.decrypt(line.strip()).decode())
            except:
                continue

๐Ÿ” 6. Search Entries by Keyword

def search_entries(keyword):
    fernet = generate_key()
    if not os.path.exists("diary.txt"):
        print("No diary entries found.")
        return

    with open("diary.txt", "rb") as file:
        lines = file.readlines()

    print(f"\n๐Ÿ”Ž Search results for '{keyword}':\n")
    for i in range(0, len(lines), 2):
        if len(lines) > i + 1:
            timestamp = lines[i].decode(errors="ignore")
            entry = fernet.decrypt(lines[i + 1].strip()).decode()
            if keyword.lower() in entry.lower():
                print(f"{timestamp}\n{entry}\n{'-' * 40}")

๐Ÿ”’ 7. Optional: Password Protection

def authenticate():
    password = "mysecret123"
    user_input = getpass.getpass("Enter diary password: ")
    if user_input != password:
        print("โŒ Incorrect password!")
        exit()

๐Ÿงฐ 8. Main Program Menu

def main():
    authenticate()  # Comment this out to disable password

    while True:
        print("\n=== Personal Diary App ===")
        print("1. Add New Entry")
        print("2. View Entries")
        print("3. Search Entries")
        print("4. Exit")

        choice = input("Choose an option: ")

        if choice == "1":
            add_entry()
        elif choice == "2":
            view_entries()
        elif choice == "3":
            keyword = input("Enter keyword to search: ")
            search_entries(keyword)
        elif choice == "4":
            print("Goodbye ๐Ÿ‘‹")
            break
        else:
            print("Invalid choice. Try again.")

if __name__ == "__main__":
    main()

๐Ÿ’ก 9. Enhancements & Ideas

  • ๐ŸชŸ Add Tkinter GUI for user-friendly interface
  • ๐Ÿ” Enable per-entry encryption passwords
  • โ˜๏ธ Sync diary entries to Google Drive or Dropbox
  • ๐Ÿ“… Add calendar view to select dates
  • ๐Ÿง  Include sentiment analysis using textblob

โœ… Summary

FeatureDescription
๐Ÿ” SecurityEncrypts entries using cryptography
๐Ÿ—“ TimestampAutomatically logs date/time
๐Ÿ“ EditingSimple file-based system
๐Ÿ” SearchKeyword-based entry lookup
โš™๏ธ ExtendableEasily add GUI or cloud sync


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *