mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-08-29 07:21:39 +02:00
Sync changes
This commit is contained in:
@@ -12,7 +12,7 @@ from pathlib import Path
|
|||||||
from mimetypes import MimeTypes
|
from mimetypes import MimeTypes
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
|
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
|
||||||
from Whatsapp_Chat_Exporter.utility import MAX_SIZE, ROW_SIZE, rendering, sanitize_except, determine_day, Crypt
|
from Whatsapp_Chat_Exporter.utility import MAX_SIZE, ROW_SIZE, Device, rendering, sanitize_except, determine_day, Crypt
|
||||||
from Whatsapp_Chat_Exporter.utility import brute_force_offset, CRYPT14_OFFSETS
|
from Whatsapp_Chat_Exporter.utility import brute_force_offset, CRYPT14_OFFSETS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -157,11 +157,11 @@ def contacts(db, data):
|
|||||||
c.execute("""SELECT jid, display_name FROM wa_contacts; """)
|
c.execute("""SELECT jid, display_name FROM wa_contacts; """)
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
while row is not None:
|
while row is not None:
|
||||||
data[row["jid"]] = ChatStore(row["display_name"])
|
data[row["jid"]] = ChatStore(Device.ANDROID, row["display_name"])
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
|
|
||||||
|
|
||||||
def messages(db, data):
|
def messages(db, data, media_folder):
|
||||||
# Get message history
|
# Get message history
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
try:
|
try:
|
||||||
@@ -251,7 +251,7 @@ def messages(db, data):
|
|||||||
break
|
break
|
||||||
while content is not None:
|
while content is not None:
|
||||||
if content["key_remote_jid"] not in data:
|
if content["key_remote_jid"] not in data:
|
||||||
data[content["key_remote_jid"]] = ChatStore()
|
data[content["key_remote_jid"]] = ChatStore(Device.ANDROID)
|
||||||
if content["key_remote_jid"] is None:
|
if content["key_remote_jid"] is None:
|
||||||
continue # Not sure
|
continue # Not sure
|
||||||
message = Message(
|
message = Message(
|
||||||
@@ -528,7 +528,8 @@ def create_html(
|
|||||||
template=None,
|
template=None,
|
||||||
embedded=False,
|
embedded=False,
|
||||||
offline_static=False,
|
offline_static=False,
|
||||||
maximum_size=None
|
maximum_size=None,
|
||||||
|
no_avatar=False
|
||||||
):
|
):
|
||||||
if template is None:
|
if template is None:
|
||||||
template_dir = os.path.dirname(__file__)
|
template_dir = os.path.dirname(__file__)
|
||||||
@@ -539,11 +540,12 @@ def create_html(
|
|||||||
templateLoader = jinja2.FileSystemLoader(searchpath=template_dir)
|
templateLoader = jinja2.FileSystemLoader(searchpath=template_dir)
|
||||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||||
templateEnv.globals.update(determine_day=determine_day)
|
templateEnv.globals.update(determine_day=determine_day)
|
||||||
|
templateEnv.globals.update(no_avatar=no_avatar)
|
||||||
templateEnv.filters['sanitize_except'] = sanitize_except
|
templateEnv.filters['sanitize_except'] = sanitize_except
|
||||||
template = templateEnv.get_template(template_file)
|
template = templateEnv.get_template(template_file)
|
||||||
|
|
||||||
total_row_number = len(data)
|
total_row_number = len(data)
|
||||||
print(f"\nCreating HTML...(0/{total_row_number})", end="\r")
|
print(f"\nGenerating chats...(0/{total_row_number})", end="\r")
|
||||||
|
|
||||||
if not os.path.isdir(output_folder):
|
if not os.path.isdir(output_folder):
|
||||||
os.mkdir(output_folder)
|
os.mkdir(output_folder)
|
||||||
@@ -602,7 +604,10 @@ def create_html(
|
|||||||
render_box,
|
render_box,
|
||||||
contact,
|
contact,
|
||||||
w3css,
|
w3css,
|
||||||
f"{safe_file_name}-{current_page + 1}.html"
|
f"{safe_file_name}-{current_page + 1}.html",
|
||||||
|
chat.my_avatar,
|
||||||
|
chat.their_avatar,
|
||||||
|
chat.their_avatar_thumb
|
||||||
)
|
)
|
||||||
render_box = [message]
|
render_box = [message]
|
||||||
current_size = 0
|
current_size = 0
|
||||||
@@ -620,17 +625,31 @@ def create_html(
|
|||||||
render_box,
|
render_box,
|
||||||
contact,
|
contact,
|
||||||
w3css,
|
w3css,
|
||||||
False
|
False,
|
||||||
|
chat.my_avatar,
|
||||||
|
chat.their_avatar,
|
||||||
|
chat.their_avatar_thumb
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
render_box.append(message)
|
render_box.append(message)
|
||||||
else:
|
else:
|
||||||
output_file_name = f"{output_folder}/{safe_file_name}.html"
|
output_file_name = f"{output_folder}/{safe_file_name}.html"
|
||||||
rendering(output_file_name, template, name, chat.get_messages(), contact, w3css, False)
|
rendering(
|
||||||
|
output_file_name,
|
||||||
|
template,
|
||||||
|
name,
|
||||||
|
chat.get_messages(),
|
||||||
|
contact,
|
||||||
|
w3css,
|
||||||
|
False,
|
||||||
|
chat.my_avatar,
|
||||||
|
chat.their_avatar,
|
||||||
|
chat.their_avatar_thumb
|
||||||
|
)
|
||||||
if current % 10 == 0:
|
if current % 10 == 0:
|
||||||
print(f"Creating HTML...({current}/{total_row_number})", end="\r")
|
print(f"Generating chats...({current}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
print(f"Creating HTML...({total_row_number}/{total_row_number})", end="\r")
|
print(f"Generating chats...({total_row_number}/{total_row_number})", end="\r")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ from datetime import datetime
|
|||||||
from mimetypes import MimeTypes
|
from mimetypes import MimeTypes
|
||||||
import os
|
import os
|
||||||
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
|
from Whatsapp_Chat_Exporter.data_model import ChatStore, Message
|
||||||
|
from Whatsapp_Chat_Exporter.utility import Device
|
||||||
|
|
||||||
|
|
||||||
def messages(path, data, assume_first_as_me=False):
|
def messages(path, data, assume_first_as_me=False):
|
||||||
"""Extracts messages from the exported file"""
|
"""Extracts messages from the exported file"""
|
||||||
with open(path, "r", encoding="utf8") as file:
|
with open(path, "r", encoding="utf8") as file:
|
||||||
you = ""
|
you = ""
|
||||||
data["ExportedChat"] = ChatStore()
|
data["ExportedChat"] = ChatStore(Device.EXPORTED)
|
||||||
chat = data["ExportedChat"]
|
chat = data["ExportedChat"]
|
||||||
total_row_number = len(file.readlines())
|
total_row_number = len(file.readlines())
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user