-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwapp_to_json.py
More file actions
48 lines (39 loc) · 1.5 KB
/
wapp_to_json.py
File metadata and controls
48 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import re
from io import StringIO
def wapp_to_json(chat_location):
pattern = "([1-9]|1[0-2])/([1-9]|[1-2][0-9]|3[0-1])/([1-9][1-9]), ([0-1][0-9]|2[0-3]):([0-5][0-9]) - "
chat = StringIO(chat_location)
chat = chat.readlines()
chat_json = []
for i in chat:
msg_arr = re.split(pattern, i)
msg_arr.pop(0)
try:
msg = msg_arr[5]
except: continue
b = ""
for a in msg:
if(a == ":"):
break
a = b + a
b = a
msg = msg.replace((b + ": "), "")
msg_dict = { "Sender": b, "Day": msg_arr[1], "Month": msg_arr[0],
"Year": msg_arr[2], "Hour": msg_arr[3], "Message": msg }
flag = 1
for i in ["changed this group", "left", "added",
"joined using this group's invite link", "removed", "can message this group",
"ERROR", "changed the subject", "changed the group", "Messages and calls are end-to-end encrypted",
"created group", "You're now", "started a call"]:
if i in msg_dict["Sender"]:
flag = 0
for i in ["<Media omitted>", "Waiting for this message", "You deleted this message", "This message was deleted"]:
if i in msg_dict["Message"]:
flag = 0
if flag == 1:
chat_json.append(msg_dict)
else:
continue
chat_json = json.dumps(chat_json, ensure_ascii=False)
return chat_json