From 9ac8839ecc61b52e00d1c2da3d6673ebb6851370 Mon Sep 17 00:00:00 2001 From: KnugiHK <24708955+KnugiHK@users.noreply.github.com> Date: Fri, 19 May 2023 13:23:51 +0800 Subject: [PATCH] Workaround for non-UTF8 message #44 --- Whatsapp_Chat_Exporter/extract.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Whatsapp_Chat_Exporter/extract.py b/Whatsapp_Chat_Exporter/extract.py index 3fcc269..0c04cbe 100644 --- a/Whatsapp_Chat_Exporter/extract.py +++ b/Whatsapp_Chat_Exporter/extract.py @@ -240,7 +240,15 @@ def messages(db, data): else: table_message = False i = 0 - content = c.fetchone() + while True: + try: + content = c.fetchone() + except sqlite3.OperationalError: + continue + else: + if content is not None and isinstance(content["data"], bytes): + continue + break while content is not None: if content["key_remote_jid"] not in data: data[content["key_remote_jid"]] = ChatStore() @@ -377,7 +385,15 @@ def messages(db, data): i += 1 if i % 1000 == 0: print(f"Gathering messages...({i}/{total_row_number})", end="\r") - content = c.fetchone() + while True: + try: + content = c.fetchone() + except sqlite3.OperationalError: + continue + else: + if content is not None and isinstance(content["data"], bytes): + continue + break print(f"Gathering messages...({total_row_number}/{total_row_number})", end="\r")