diff --git a/Whatsapp_Chat_Exporter/__main__.py b/Whatsapp_Chat_Exporter/__main__.py index e693727..a62d317 100644 --- a/Whatsapp_Chat_Exporter/__main__.py +++ b/Whatsapp_Chat_Exporter/__main__.py @@ -269,7 +269,7 @@ def validate_args(parser: ArgumentParser, args) -> None: # Basic validation checks if args.android and args.ios and args.exported and args.import_json: parser.error("You must define only one device type.") - if not args.android and not args.ios and not args.exported and not args.import_json: + if not args.android and not args.ios and not args.exported and not args.import_json and not args.incremental_merge: parser.error("You must define the device type.") if args.no_html and not args.json and not args.text_format: parser.error("You must either specify a JSON output file, text file output directory or enable HTML output.") @@ -748,7 +748,14 @@ def main(): args.wa = "ContactsV2.sqlite" if args.incremental_merge: - incremental_merge(args.source_dir, args.target_dir, args.media) + incremental_merge( + args.source_dir, + args.target_dir, + args.media, + args.pretty_print_json, + args.avoid_encoding_json + ) + print("Incremental merge completed successfully.") else: # Process contacts process_contacts(args, data, contact_store) @@ -766,4 +773,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/Whatsapp_Chat_Exporter/utility.py b/Whatsapp_Chat_Exporter/utility.py index 3e5e70f..b3303bd 100644 --- a/Whatsapp_Chat_Exporter/utility.py +++ b/Whatsapp_Chat_Exporter/utility.py @@ -259,7 +259,7 @@ def import_from_json(json_file: str, data: Dict[str, ChatStore]): print(f"Importing chats from JSON...({index + 1}/{total_row_number})", end="\r") -def incremental_merge(source_dir: str, target_dir: str, media_dir: str): +def incremental_merge(source_dir: str, target_dir: str, media_dir: str, pretty_print_json: int, avoid_encoding_json: bool): """Merges JSON files from the source directory into the target directory. Args: @@ -303,7 +303,12 @@ def incremental_merge(source_dir: str, target_dir: str, media_dir: str): if json.dumps(merged_data, sort_keys=True) != json.dumps(target_data, sort_keys=True): print(f"Changes detected in '{json_file}', updating target file...") with open(target_path, 'w') as merged_file: - json.dump(merged_data, merged_file, indent=2) + json.dump( + merged_data, + merged_file, + indent=pretty_print_json, + ensure_ascii=not avoid_encoding_json, + ) else: print(f"No changes detected in '{json_file}', skipping update.")