diff --git a/Whatsapp_Chat_Exporter/__main__.py b/Whatsapp_Chat_Exporter/__main__.py index 31ef6cf..ac1d3dc 100644 --- a/Whatsapp_Chat_Exporter/__main__.py +++ b/Whatsapp_Chat_Exporter/__main__.py @@ -316,6 +316,12 @@ def main(): const="1b432994e958845fffe8e2f190f26d1511534088", help="Path to call database (default: 1b432994e958845fffe8e2f190f26d1511534088) iOS only" ) + parser.add_argument( + "--headline", + dest="headline", + default="Chat history with ??", + help="The custom headline for the HTML output. Use '??' as a placeholder for the chat name" + ) args = parser.parse_args() @@ -336,6 +342,8 @@ def main(): parser.error("JSON file not found.") if args.android and args.business: parser.error("WhatsApp Business is only available on iOS for now.") + if "??" not in args.headline: + parser.error("--headline must contain '??' for replacement.") if args.json_per_chat and ( (args.json[-5:] != ".json" and os.path.isfile(args.json)) or \ (args.json[-5:] == ".json" and os.path.isfile(args.json[:-5])) @@ -527,7 +535,8 @@ def main(): args.offline, args.size, args.no_avatar, - args.whatsapp_theme + args.whatsapp_theme, + args.headline ) else: print( @@ -564,7 +573,8 @@ def main(): args.offline, args.size, args.no_avatar, - args.whatsapp_theme + args.whatsapp_theme, + args.headline ) for file in glob.glob(r'*.*'): shutil.copy(file, args.output) @@ -578,7 +588,8 @@ def main(): args.offline, args.size, args.no_avatar, - args.whatsapp_theme + args.whatsapp_theme, + args.headline ) if args.text_format: diff --git a/Whatsapp_Chat_Exporter/android_handler.py b/Whatsapp_Chat_Exporter/android_handler.py index 3e4db44..62b0665 100644 --- a/Whatsapp_Chat_Exporter/android_handler.py +++ b/Whatsapp_Chat_Exporter/android_handler.py @@ -779,7 +779,8 @@ def create_html( offline_static=False, maximum_size=None, no_avatar=False, - experimental=False + experimental=False, + headline=None ): template = setup_template(template, no_avatar, experimental) @@ -817,7 +818,8 @@ def create_html( contact, w3css, f"{safe_file_name}-{current_page + 1}.html", - chat + chat, + headline ) render_box = [message] current_size = 0 @@ -837,7 +839,8 @@ def create_html( contact, w3css, False, - chat + chat, + headline ) else: output_file_name = f"{output_folder}/{safe_file_name}.html" @@ -849,7 +852,8 @@ def create_html( contact, w3css, False, - chat + chat, + headline ) if current % 10 == 0: print(f"Generating chats...({current}/{total_row_number})", end="\r") diff --git a/Whatsapp_Chat_Exporter/utility.py b/Whatsapp_Chat_Exporter/utility.py index 0a3c7f9..86ef9af 100644 --- a/Whatsapp_Chat_Exporter/utility.py +++ b/Whatsapp_Chat_Exporter/utility.py @@ -134,11 +134,15 @@ def rendering( w3css, next, chat, + headline ): if chat.their_avatar_thumb is None and chat.their_avatar is not None: their_avatar_thumb = chat.their_avatar else: their_avatar_thumb = chat.their_avatar_thumb + if "??" not in headline: + raise ValueError("Headline must contain '??' to replace with name") + headline = headline.replace("??", name) with open(output_file_name, "w", encoding="utf-8") as f: f.write( template.render( @@ -150,7 +154,8 @@ def rendering( w3css=w3css, next=next, status=chat.status, - media_base=chat.media_base + media_base=chat.media_base, + headline=headline ) ) diff --git a/Whatsapp_Chat_Exporter/whatsapp.html b/Whatsapp_Chat_Exporter/whatsapp.html index 953ede4..0de948f 100644 --- a/Whatsapp_Chat_Exporter/whatsapp.html +++ b/Whatsapp_Chat_Exporter/whatsapp.html @@ -90,7 +90,7 @@
{{ status }}
{% endif %}