From 92ccd641c4ce1c26a1eb2a0992719982e548d470 Mon Sep 17 00:00:00 2001 From: Knugi <24708955+KnugiHK@users.noreply.github.com> Date: Sun, 10 Jan 2021 13:56:45 +0000 Subject: [PATCH] Add files via upload --- extract.py | 39 +++++++++++++++++++++++++++++++++++++++ whatsapp.html | 25 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 extract.py create mode 100644 whatsapp.html diff --git a/extract.py b/extract.py new file mode 100644 index 0000000..91d8090 --- /dev/null +++ b/extract.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 + +import sqlite3 +import sys +import json +import jinja2 + +data = {} +wa = sqlite3.connect("wa.db") + +c = wa.cursor() +c.execute("""SELECT jid, display_name FROM "main"."wa_contacts"; """) +row = c.fetchone() +while row is not None: + data[row[0]] = {"name": row[1], "messages":{}} + row = c.fetchone() + +msg = sqlite3.connect("msgstore.db") +c = msg.cursor() + +c.execute("""SELECT key_remote_jid, _id, key_from_me, data FROM "main"."messages"; """) +content = c.fetchone() +while content is not None: + if content[0] not in data: + data[content[0]] = {"name": None, "messages": {}} + data[content[0]]["messages"][content[1]] = {"from_me": bool(content[2]), "data": content[3]} + content = c.fetchone() + +templateLoader = jinja2.FileSystemLoader(searchpath="./") +templateEnv = jinja2.Environment(loader=templateLoader) +TEMPLATE_FILE = "whatsapp.html" +template = templateEnv.get_template(TEMPLATE_FILE) + +for i in data: + with open(f"temp/{i.split('@')[0]}.html", "w", encoding="utf-8") as f: + f.write(template.render(name=data[i]["name"], msgs=data[i]["messages"].values())) + +with open("result.json", "w") as f: + f.write(json.dumps(data)) \ No newline at end of file diff --git a/whatsapp.html b/whatsapp.html new file mode 100644 index 0000000..b4d3fc8 --- /dev/null +++ b/whatsapp.html @@ -0,0 +1,25 @@ + + + + Whatsapp - {{ name }} + + + +

Chat history with {{ name }}

+
+ +
+ {% for msg in msgs -%} +
+ {% if msg.from_me == true %} + + {% else %} + + {% endif %} + + {% endfor %} + +
{{ msg.data }}{{ msg.data }}
+
+ + \ No newline at end of file