From 746d8380cb41abf85f141870d908fc4b60457f38 Mon Sep 17 00:00:00 2001 From: Lain Date: Fri, 24 Jan 2025 17:00:07 -0300 Subject: [PATCH] allow multiple rooms --- README.md | 5 ++--- megolm_filter.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3505377..621f01e 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,10 @@ options: -p, --plain Returns the plain unencrypted content ``` -Using the above example, let's say we want to only get session keys of the room -`!foo:matrix.org`. You can do this fairly easily with: +You can do this fairly easily with: ```bash - $ ./megolm_filter.py element-keys.txt '!foo:matrix.org' + $ ./megolm_filter.py element-keys.txt '!room1:matrix.org' '!room2:matrix.org' ... ``` You need to have PyCryptodome installed in order for this script to work. diff --git a/megolm_filter.py b/megolm_filter.py index 0973c4d..d8f94c3 100755 --- a/megolm_filter.py +++ b/megolm_filter.py @@ -145,7 +145,7 @@ def dec_session_data(passphrase, session_data): def main(): parser = argparse.ArgumentParser(description="Operate on megolm session backups.") parser.add_argument("file", nargs='?', help="megolm session data") - parser.add_argument("room_id", nargs='?', help="Room id to filter (optional)") + parser.add_argument("room_ids", nargs='*', help="Room id to filter (optional)") parser.add_argument("-o", "--output", help="Output to file") parser.add_argument("-p", "--plain", dest="mode", const="plain", action="store_const", help="Returns the plain unencrypted content") @@ -166,9 +166,9 @@ def main(): passphrase = getpass.getpass(f"Backup passphrase [mode={args.mode}]: ") decrypted_data = dec_session_data(passphrase, data) - if args.room_id: + if args.room_ids: json_data = json.loads(decrypted_data) - filtered_data = [ key for key in json_data if key['room_id'] == args.room_id ] + filtered_data = [ key for key in json_data if key['room_id'] in args.room_ids ] if not filtered_data: bail(f"No keys found for room {args.room_id}")