Implement custom headline (#97)

This commit is contained in:
KnugiHK
2025-02-09 14:20:11 +08:00
parent 539a1d58b0
commit 0b2dfa9aba
5 changed files with 30 additions and 10 deletions

View File

@@ -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:

View File

@@ -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")

View File

@@ -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
)
)

View File

@@ -90,7 +90,7 @@
</head>
<body>
<header class="w3-center w3-top">
Chat history with {{ name }}
{{ headline }}
{% if status is not none %}
<br>
<span class="w3-small">{{ status }}</span>

View File

@@ -153,7 +153,7 @@
</div>
{% endif %}
<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 %}
</div>
</div>