Rams Poster
Ready for a tiny but mighty project you can finish in one sitting?
Create a Command‑Line Daily Journal that lets you jot down thoughts, ideas, or anything you want to remember – and saves each entry to a nicely‑formatted markdown file with a timestamp. No GUI, no databases, just pure Python and the power of plain text.
Why this works
- File handling (open, write, close) lets you append data to a file without overwriting the old stuff.
- datetime gives you the exact date and time, so each entry is clearly marked.
- pathlib (the modern way to work with paths) makes the script portable across Windows, macOS, and Linux.
- The whole thing runs in the terminal, so you can launch it from any shell or even bind it to a keyboard shortcut.
How you’ll build it
1. Ask the user for a journal entry.
Use a simple loop that reads lines until the user submits an empty line (just hit Enter).
2. Add a header with the current date & time.
datetime.now().strftime("%Y-%m-%d %H:%M") formats the timestamp the way we like to see it.
3. Append the entry to a markdown file.
Opening the file with mode 'a' (append) ensures previous entries stay untouched.
4. Store the file in a dedicated folder.
With pathlib.Path.home() / "journal" you automatically place the journal in the user’s home directory, keeping everything tidy.
What you’ll learn
- Converting user input into a multi‑line string.
- Using with open(...) as f: to safely manage file resources (no need to call close).
- Formatting strings with f‑strings (you may already know them, but they shine here).
- Creating directories on the fly if they don’t exist (Path.mkdir(parents=True, exist_ok=True)).
A quick sketch of the code
import sys
from datetime import datetime
from pathlib import Path
# ---------- configuration ----------
journal_dir = Path.home() / "journal"
journal_file = journal_dir / "daily.md"
journal_dir.mkdir(parents=True, exist_ok=True)
# -----------------------------------
def collect_entry():
print("Enter your journal entry. Press Enter on an empty line to finish.")
lines = []
for line in sys.stdin:
line = line.rstrip("\n")
if line == "":
break
lines.append(line)
return "\n".join(lines)
def save_entry(text: str):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
header = f"\n## {timestamp}\n\n"
with journal_file.open("a", encoding="utf-8") as f:
f.write(header + text + "\n")
if __name__ == "__main__":
entry = collect_entry()
if entry.strip():
save_entry(entry)
print(f"✅ Entry saved to {journal_file}")
else:
print("⚠️ No text entered – nothing saved.")
Give it a spin
1. Save the script as journal.py.
2. Run it: python journal.py.
3. Type a few lines, hit Enter on a blank line, and watch the markdown file grow.
Next steps (optional)
- Add a --list flag to print the last 5 entries.
- Use the rich library to colour‑code the terminal output.
- Convert the markdown to HTML for a simple web‑based view.
That’s it – a functional, personal journal you can start using right away, and a solid foundation for many future tweaks. Happy writing!
5 ·