Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.backup
*.jex
*.json

52 changes: 52 additions & 0 deletions exclude_by_color_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path


def parse_args():
parser = argparse.ArgumentParser(
description="Copy a ColorNote JSON export while excluding notes by color_index."
)
parser.add_argument(
"input_file",
type=Path,
help="Source JSON file produced by the ColorNote decrypt script.",
)
parser.add_argument(
"output_file",
type=Path,
help="Destination JSON file.",
)
parser.add_argument(
"--exclude-color-index",
type=int,
required=True,
help="color_index value to exclude from the copied JSON.",
)
return parser.parse_args()


def main():
args = parse_args()
notes = json.loads(args.input_file.read_text(encoding="utf-8-sig"))

kept = [
note for note in notes
if note.get("color_index") != args.exclude_color_index
]

args.output_file.write_text(
json.dumps(kept, ensure_ascii=False, indent=2),
encoding="utf-8-sig",
)

removed = len(notes) - len(kept)
print(f"Input records: {len(notes)}")
print(f"Removed color_index={args.exclude_color_index}: {removed}")
print(f"Output records: {len(kept)}")
print(f"Wrote: {args.output_file}")


if __name__ == "__main__":
main()