๐ฏ 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
| Feature | Description |
|---|---|
| ๐ Security | Encrypts entries using cryptography |
| ๐ Timestamp | Automatically logs date/time |
| ๐ Editing | Simple file-based system |
| ๐ Search | Keyword-based entry lookup |
| โ๏ธ Extendable | Easily add GUI or cloud sync |

Leave a Reply