Coverage for health / cli / obsidian.py: 0%
30 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-02 17:44 +0800
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-02 17:44 +0800
1import click
2from datetime import date, datetime
3from typing import Optional
5from health.services.obsidian import ObsidianSyncService
6from health.utils.logging_config import setup_logger
8logger = setup_logger(__name__)
10@click.group()
11def cli() -> None:
12 """Obsidian Sync CLI."""
13 pass
15@cli.command()
16@click.option(
17 "--date",
18 "target_date",
19 type=click.DateTime(formats=["%Y-%m-%d"]),
20 default=datetime.now().strftime("%Y-%m-%d"),
21 help="Date to sync (YYYY-MM-DD), defaults to today",
22)
23def sync(target_date: datetime) -> None:
24 """Sync health data from Obsidian daily note for a specific date."""
25 service = ObsidianSyncService()
26 target_date_obj = target_date.date()
28 click.echo(f"🔄 Syncing Obsidian data for {target_date_obj}...")
29 success = service.sync_daily_note(target_date_obj)
31 if success:
32 click.echo("✅ Sync complete!")
33 else:
34 click.echo("⚠️ Sync failed or no file found.")
36@cli.command()
37def sync_today() -> None:
38 """Sync today's Obsidian note (convenience command)."""
39 service = ObsidianSyncService()
40 today = date.today()
42 click.echo(f"🔄 Syncing Obsidian data for today ({today})...")
43 success = service.sync_daily_note(today)
45 if success:
46 click.echo("✅ Sync complete!")
47 else:
48 click.echo("⚠️ Sync failed or no file found.")
50if __name__ == "__main__":
51 cli()