From 87fb7ea46bf51040b82ee1dae8d1309b237dd5a6 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Thu, 9 Jul 2026 00:25:16 +0400 Subject: [PATCH] Add ColorNote color index filter --- .gitignore | 4 +++ exclude_by_color_index.py | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 exclude_by_color_index.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8bc62cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.backup +*.jex +*.json + diff --git a/exclude_by_color_index.py b/exclude_by_color_index.py new file mode 100644 index 0000000..277f396 --- /dev/null +++ b/exclude_by_color_index.py @@ -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()