|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Personal Journal Entry Generator |
| 4 | +Generates daily writing prompts to help users reflect on their day. |
| 5 | +
|
| 6 | +Author: Contributing to 100LinesOfPythonCode |
| 7 | +Issue: #768 |
| 8 | +""" |
| 9 | + |
| 10 | +import random |
| 11 | +from datetime import datetime |
| 12 | +import json |
| 13 | +import os |
| 14 | + |
| 15 | +# Collection of thoughtful journal prompts organized by category |
| 16 | +PROMPTS = { |
| 17 | + "gratitude": [ |
| 18 | + "What are three things you're grateful for today?", |
| 19 | + "Who made a positive impact on your day and why?", |
| 20 | + "What simple pleasure brought you joy today?", |
| 21 | + ], |
| 22 | + "reflection": [ |
| 23 | + "What was the most challenging moment today and how did you handle it?", |
| 24 | + "What did you learn about yourself today?", |
| 25 | + "How did you grow or improve today?", |
| 26 | + ], |
| 27 | + "goals": [ |
| 28 | + "What progress did you make toward your goals today?", |
| 29 | + "What's one thing you want to accomplish tomorrow?", |
| 30 | + "What obstacle can you plan to overcome this week?", |
| 31 | + ], |
| 32 | + "creativity": [ |
| 33 | + "If today were a movie, what would be its title and genre?", |
| 34 | + "Describe your day using only metaphors.", |
| 35 | + "What would your future self thank you for doing today?", |
| 36 | + ], |
| 37 | + "mindfulness": [ |
| 38 | + "What emotions did you experience most strongly today?", |
| 39 | + "What moment today deserves to be remembered?", |
| 40 | + "How did you take care of yourself today?", |
| 41 | + ] |
| 42 | +} |
| 43 | + |
| 44 | +def get_daily_prompt(category=None): |
| 45 | + """Generate a random prompt, optionally from a specific category.""" |
| 46 | + if category and category in PROMPTS: |
| 47 | + return random.choice(PROMPTS[category]) |
| 48 | + # If no category specified, choose from all prompts |
| 49 | + all_prompts = [prompt for prompts in PROMPTS.values() for prompt in prompts] |
| 50 | + return random.choice(all_prompts) |
| 51 | + |
| 52 | +def display_prompt_with_timestamp(): |
| 53 | + """Display a prompt with the current date and time.""" |
| 54 | + now = datetime.now() |
| 55 | + date_str = now.strftime("%Y-%m-%d") |
| 56 | + time_str = now.strftime("%I:%M %p") |
| 57 | + |
| 58 | + print(f"\n{'='*60}") |
| 59 | + print(f"Journal Entry - {date_str} at {time_str}") |
| 60 | + print(f"{'='*60}\n") |
| 61 | + |
| 62 | + # Select a random category and prompt |
| 63 | + category = random.choice(list(PROMPTS.keys())) |
| 64 | + prompt = get_daily_prompt(category) |
| 65 | + |
| 66 | + print(f"Category: {category.title()}") |
| 67 | + print(f"\nToday's Prompt:\n{prompt}\n") |
| 68 | + print(f"{'='*60}\n") |
| 69 | + |
| 70 | +def save_entry(prompt, entry_text, filename="journal_entries.json"): |
| 71 | + """Save journal entry to a JSON file.""" |
| 72 | + entry = { |
| 73 | + "timestamp": datetime.now().isoformat(), |
| 74 | + "prompt": prompt, |
| 75 | + "entry": entry_text |
| 76 | + } |
| 77 | + |
| 78 | + # Load existing entries if file exists |
| 79 | + entries = [] |
| 80 | + if os.path.exists(filename): |
| 81 | + with open(filename, 'r') as f: |
| 82 | + entries = json.load(f) |
| 83 | + |
| 84 | + entries.append(entry) |
| 85 | + |
| 86 | + with open(filename, 'w') as f: |
| 87 | + json.dump(entries, f, indent=2) |
| 88 | + |
| 89 | + print(f"Entry saved to {filename}") |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + display_prompt_with_timestamp() |
0 commit comments