Add files via upload

This commit is contained in:
Knugi
2021-01-10 13:56:45 +00:00
committed by GitHub
parent 661d12cac4
commit 92ccd641c4
2 changed files with 64 additions and 0 deletions

39
extract.py Normal file
View File

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

25
whatsapp.html Normal file
View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Whatsapp - {{ name }}</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
<h1 class="w3-center w3-top" style="position:sticky">Chat history with {{ name }}</h1>
<div class="w3-container w3-sand w3-center" style="width:60%;margin:auto;z-index: 999999;">
<table class="w3-center" style="width:100%;margin-right:;">
<div style="width:100%">
{% for msg in msgs -%}
<tr>
{% if msg.from_me == true %}
<td style="text-align: right;height:auto;">{{ msg.data }}</td>
{% else %}
<td style="text-align: left;height:auto;">{{ msg.data }}</td>
{% endif %}
</tr>
{% endfor %}
</div>
</table>
</div>
</body>
</html>