mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-04-24 15:01:36 +00:00
Implement custom headline (#97)
This commit is contained in:
@@ -316,6 +316,12 @@ def main():
|
|||||||
const="1b432994e958845fffe8e2f190f26d1511534088",
|
const="1b432994e958845fffe8e2f190f26d1511534088",
|
||||||
help="Path to call database (default: 1b432994e958845fffe8e2f190f26d1511534088) iOS only"
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -336,6 +342,8 @@ def main():
|
|||||||
parser.error("JSON file not found.")
|
parser.error("JSON file not found.")
|
||||||
if args.android and args.business:
|
if args.android and args.business:
|
||||||
parser.error("WhatsApp Business is only available on iOS for now.")
|
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 (
|
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)) or \
|
||||||
(args.json[-5:] == ".json" and os.path.isfile(args.json[:-5]))
|
(args.json[-5:] == ".json" and os.path.isfile(args.json[:-5]))
|
||||||
@@ -527,7 +535,8 @@ def main():
|
|||||||
args.offline,
|
args.offline,
|
||||||
args.size,
|
args.size,
|
||||||
args.no_avatar,
|
args.no_avatar,
|
||||||
args.whatsapp_theme
|
args.whatsapp_theme,
|
||||||
|
args.headline
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
@@ -564,7 +573,8 @@ def main():
|
|||||||
args.offline,
|
args.offline,
|
||||||
args.size,
|
args.size,
|
||||||
args.no_avatar,
|
args.no_avatar,
|
||||||
args.whatsapp_theme
|
args.whatsapp_theme,
|
||||||
|
args.headline
|
||||||
)
|
)
|
||||||
for file in glob.glob(r'*.*'):
|
for file in glob.glob(r'*.*'):
|
||||||
shutil.copy(file, args.output)
|
shutil.copy(file, args.output)
|
||||||
@@ -578,7 +588,8 @@ def main():
|
|||||||
args.offline,
|
args.offline,
|
||||||
args.size,
|
args.size,
|
||||||
args.no_avatar,
|
args.no_avatar,
|
||||||
args.whatsapp_theme
|
args.whatsapp_theme,
|
||||||
|
args.headline
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.text_format:
|
if args.text_format:
|
||||||
|
|||||||
@@ -779,7 +779,8 @@ def create_html(
|
|||||||
offline_static=False,
|
offline_static=False,
|
||||||
maximum_size=None,
|
maximum_size=None,
|
||||||
no_avatar=False,
|
no_avatar=False,
|
||||||
experimental=False
|
experimental=False,
|
||||||
|
headline=None
|
||||||
):
|
):
|
||||||
template = setup_template(template, no_avatar, experimental)
|
template = setup_template(template, no_avatar, experimental)
|
||||||
|
|
||||||
@@ -817,7 +818,8 @@ def create_html(
|
|||||||
contact,
|
contact,
|
||||||
w3css,
|
w3css,
|
||||||
f"{safe_file_name}-{current_page + 1}.html",
|
f"{safe_file_name}-{current_page + 1}.html",
|
||||||
chat
|
chat,
|
||||||
|
headline
|
||||||
)
|
)
|
||||||
render_box = [message]
|
render_box = [message]
|
||||||
current_size = 0
|
current_size = 0
|
||||||
@@ -837,7 +839,8 @@ def create_html(
|
|||||||
contact,
|
contact,
|
||||||
w3css,
|
w3css,
|
||||||
False,
|
False,
|
||||||
chat
|
chat,
|
||||||
|
headline
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
output_file_name = f"{output_folder}/{safe_file_name}.html"
|
output_file_name = f"{output_folder}/{safe_file_name}.html"
|
||||||
@@ -849,7 +852,8 @@ def create_html(
|
|||||||
contact,
|
contact,
|
||||||
w3css,
|
w3css,
|
||||||
False,
|
False,
|
||||||
chat
|
chat,
|
||||||
|
headline
|
||||||
)
|
)
|
||||||
if current % 10 == 0:
|
if current % 10 == 0:
|
||||||
print(f"Generating chats...({current}/{total_row_number})", end="\r")
|
print(f"Generating chats...({current}/{total_row_number})", end="\r")
|
||||||
|
|||||||
@@ -134,11 +134,15 @@ def rendering(
|
|||||||
w3css,
|
w3css,
|
||||||
next,
|
next,
|
||||||
chat,
|
chat,
|
||||||
|
headline
|
||||||
):
|
):
|
||||||
if chat.their_avatar_thumb is None and chat.their_avatar is not None:
|
if chat.their_avatar_thumb is None and chat.their_avatar is not None:
|
||||||
their_avatar_thumb = chat.their_avatar
|
their_avatar_thumb = chat.their_avatar
|
||||||
else:
|
else:
|
||||||
their_avatar_thumb = chat.their_avatar_thumb
|
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:
|
with open(output_file_name, "w", encoding="utf-8") as f:
|
||||||
f.write(
|
f.write(
|
||||||
template.render(
|
template.render(
|
||||||
@@ -150,7 +154,8 @@ def rendering(
|
|||||||
w3css=w3css,
|
w3css=w3css,
|
||||||
next=next,
|
next=next,
|
||||||
status=chat.status,
|
status=chat.status,
|
||||||
media_base=chat.media_base
|
media_base=chat.media_base,
|
||||||
|
headline=headline
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="w3-center w3-top">
|
<header class="w3-center w3-top">
|
||||||
Chat history with {{ name }}
|
{{ headline }}
|
||||||
{% if status is not none %}
|
{% if status is not none %}
|
||||||
<br>
|
<br>
|
||||||
<span class="w3-small">{{ status }}</span>
|
<span class="w3-small">{{ status }}</span>
|
||||||
|
|||||||
@@ -153,7 +153,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-white font-medium">Chat history with {{ name }}</h2>
|
<h2 class="text-white font-medium">{{ headline }}</h2>
|
||||||
{% if status is not none %}<p class="text-[#8696a0] text-xs">{{ status }}</p>{% endif %}
|
{% if status is not none %}<p class="text-[#8696a0] text-xs">{{ status }}</p>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user