added option to delete a daily through application at remo

This commit is contained in:
Niki Vihtola
2025-12-12 15:07:40 +02:00
parent e154a067c3
commit 082a7e0b47
4 changed files with 67 additions and 1 deletions

View File

@@ -68,6 +68,11 @@ jrnl daily --days 2
# Regenerate today's standup # Regenerate today's standup
jrnl daily --regenerate jrnl daily --regenerate
# Delete a daily entry
jrnl daily --delete 2024-12-12
jrnl daily --delete today
jrnl daily --delete latest
``` ```
### Configuration Management ### Configuration Management

View File

@@ -58,6 +58,11 @@ Examples:
# Generate standup including last 2 days # Generate standup including last 2 days
jrnl daily --days 2 jrnl daily --days 2
# Delete a daily entry
jrnl daily --delete 2024-12-12
jrnl daily --delete today
jrnl daily --delete latest
''', ''',
formatter_class=argparse.RawDescriptionHelpFormatter formatter_class=argparse.RawDescriptionHelpFormatter
) )
@@ -65,6 +70,8 @@ Examples:
help='Number of days to include (default: 1)') help='Number of days to include (default: 1)')
daily_parser.add_argument('-r', '--regenerate', action='store_true', daily_parser.add_argument('-r', '--regenerate', action='store_true',
help='Regenerate today\'s standup with latest logs') help='Regenerate today\'s standup with latest logs')
daily_parser.add_argument('--delete', metavar='DATE',
help='Delete a daily entry (DATE: YYYY-MM-DD, "today", or "latest")')
# jrnl logs # jrnl logs
logs_parser = subparsers.add_parser( logs_parser = subparsers.add_parser(

View File

@@ -5,7 +5,9 @@ from ..database.operations import (
get_logs_since, get_logs_since,
get_latest_daily, get_latest_daily,
get_previous_daily_before, get_previous_daily_before,
insert_daily get_daily_for_date,
insert_daily,
delete_daily
) )
from ..database.models import Daily from ..database.models import Daily
from ..config import Config from ..config import Config
@@ -17,6 +19,10 @@ from ..utils.formatting import format_daily_header
def handle(args): def handle(args):
"""Handle the 'daily' command.""" """Handle the 'daily' command."""
try: try:
# Handle deletion if requested
if hasattr(args, 'delete') and args.delete:
return handle_delete(args.delete)
config = Config.load() config = Config.load()
# Determine date range for logs # Determine date range for logs
@@ -77,6 +83,46 @@ def handle(args):
return 1 return 1
def handle_delete(date_arg: str) -> int:
"""Handle deleting a daily entry."""
try:
# Resolve date argument
if date_arg.lower() in ['today', 'latest']:
# Get today's date or latest daily date
if date_arg.lower() == 'today':
date = get_current_date()
else:
latest = get_latest_daily()
if not latest:
print("No daily entries found.")
return 1
date = latest.daily_date
else:
# Assume it's a date in YYYY-MM-DD format
date = date_arg
# Check if daily exists
daily = get_daily_for_date(date)
if not daily:
print(f"No daily found for date: {date}")
return 1
# Delete the daily
if delete_daily(date):
print(f"Deleted daily for {date}")
return 0
else:
print(f"Failed to delete daily for {date}")
return 1
except sqlite3.Error as e:
print(f"Database error: {e}")
return 1
except Exception as e:
print(f"Error deleting daily: {e}")
return 1
def get_normal_cutoff(): def get_normal_cutoff():
"""Get cutoff timestamp for normal daily generation.""" """Get cutoff timestamp for normal daily generation."""
latest_daily = get_latest_daily() latest_daily = get_latest_daily()

View File

@@ -158,3 +158,11 @@ def get_previous_daily_before(date: str) -> Optional[Daily]:
daily_message=row['daily_message'] daily_message=row['daily_message']
) )
return None return None
def delete_daily(date: str) -> bool:
"""Delete a daily entry by its date. Returns True if deleted, False if not found."""
with get_connection() as conn:
cursor = conn.cursor()
cursor.execute('DELETE FROM dailies WHERE daily_date = ?', (date,))
return cursor.rowcount > 0