MCPcopy Create free account
hub / github.com/dogsheep/apple-notes-to-sqlite / cli

Function cli

apple_notes_to_sqlite/cli.py:44–71  ·  view source on GitHub ↗

Export Apple Notes to SQLite

(db_path, stop_after, dump)

Source from the content-addressed store, hash-verified

42@click.option("--stop-after", type=int, help="Stop after this many notes")
43@click.option("--dump", is_flag=True, help="Output notes to standard output")
44def cli(db_path, stop_after, dump):
45 "Export Apple Notes to SQLite"
46 if not db_path and not dump:
47 raise click.UsageError(
48 "Please specify a path to a database file, or use --dump to see the output",
49 )
50 expected_count = stop_after
51 if not expected_count:
52 expected_count = count_notes()
53 # Use click progressbar
54 i = 0
55 if dump:
56 for note in extract_notes():
57 click.echo(json.dumps(note))
58 i += 1
59 if stop_after and i >= stop_after:
60 break
61 else:
62 db = sqlite_utils.Database(db_path)
63 with click.progressbar(
64 length=expected_count, label="Exporting notes", show_eta=True, show_pos=True
65 ) as bar:
66 for note in extract_notes():
67 db["notes"].insert(note, pk="id", replace=True)
68 bar.update(1)
69 i += 1
70 if stop_after and i >= stop_after:
71 break
72
73
74def count_notes():

Callers 1

__main__.pyFile · 0.90

Calls 2

count_notesFunction · 0.85
extract_notesFunction · 0.85

Tested by

no test coverage detected