mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-25 23:41:33 +00:00
Respects users' choices on the output JSON
This commit is contained in:
@@ -269,7 +269,7 @@ def validate_args(parser: ArgumentParser, args) -> None:
|
|||||||
# Basic validation checks
|
# Basic validation checks
|
||||||
if args.android and args.ios and args.exported and args.import_json:
|
if args.android and args.ios and args.exported and args.import_json:
|
||||||
parser.error("You must define only one device type.")
|
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.")
|
parser.error("You must define the device type.")
|
||||||
if args.no_html and not args.json and not args.text_format:
|
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.")
|
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"
|
args.wa = "ContactsV2.sqlite"
|
||||||
|
|
||||||
if args.incremental_merge:
|
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:
|
else:
|
||||||
# Process contacts
|
# Process contacts
|
||||||
process_contacts(args, data, contact_store)
|
process_contacts(args, data, contact_store)
|
||||||
@@ -766,4 +773,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -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")
|
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.
|
"""Merges JSON files from the source directory into the target directory.
|
||||||
|
|
||||||
Args:
|
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):
|
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...")
|
print(f"Changes detected in '{json_file}', updating target file...")
|
||||||
with open(target_path, 'w') as merged_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:
|
else:
|
||||||
print(f"No changes detected in '{json_file}', skipping update.")
|
print(f"No changes detected in '{json_file}', skipping update.")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user