Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 6500925

Browse files
committed
Improve text parsing for old formats & version bump to 3.0.7
1 parent 42925b1 commit 6500925

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

requirements.txt

0 Bytes
Binary file not shown.

src/TLImporter.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from telethon.sessions import *
1717
from telethon.utils import get_display_name
1818

19-
__version__ = '3.0.6'
19+
__version__ = '3.0.7'
2020
api_id = YOUR_API_ID_HERE
2121
api_hash = 'YOUR_API_HASH_HERE'
2222
TLdevice_model = 'Desktop device'
@@ -570,6 +570,12 @@ def DumpDB():
570570
msg = []
571571
multilinemsg = False
572572
for l in f:
573+
try:
574+
if l == '\n' and len(msg[3]) > 0:
575+
msg[3] = msg[3] + '\n'
576+
continue
577+
except IndexError:
578+
pass
573579
completed += 1
574580
index = None
575581
header = ""
@@ -588,6 +594,23 @@ def DumpDB():
588594
break
589595
if notfound and len(msg) == 0:
590596
continue
597+
598+
if index is not None:
599+
# Do a final check for old formats that WhatsApp doesn't use anymore
600+
if splitted[index] != NameUser1 and splitted[index] != NameUser2:
601+
matches = pattern.findall(splitted[index])
602+
matchedString = ''
603+
for i in matches:
604+
if i != ' ':
605+
matchedString = matchedString + i
606+
if len(matches) > 0:
607+
splitted.insert(0, matchedString)
608+
del matchedString
609+
if found_user1:
610+
splitted[1] = NameUser1
611+
else:
612+
splitted[1] = NameUser2
613+
index = 1
591614

592615
# Now, we check if what's behind the name are only numbers or non alpha characters. If that's the case,
593616
# we discard it as being a new message: it's a multiline message instead (or a copy from another message).
@@ -614,6 +637,8 @@ def DumpDB():
614637
continue
615638
elif found_user1 or found_user2:
616639
if len(msg) > 0:
640+
if msg[3][-1] != "\n":
641+
msg[3] += "\n"
617642
reg = (msg[0], msg[1], msg[2], msg[3])
618643
db.execute("INSERT INTO ImportedMessages VALUES(?,?,?,?)", reg)
619644
msg.clear()
@@ -717,12 +742,20 @@ def ExportMessages():
717742
Sender = "`" + row[1] + ":`\n"
718743
else:
719744
Sender = None
720-
if EndDate:
721-
Date = "`[" + row[2] + "]`"
722-
elif SoloImporting:
723-
Date = "`[" + row[2] + "] " + row[1] + ":`\n"
745+
if row[2][0] != "[" and row[2][-1] != "]":
746+
if EndDate:
747+
Date = "`[" + row[2] + "]`"
748+
elif SoloImporting:
749+
Date = "`[" + row[2] + "] " + row[1] + ":`\n"
750+
else:
751+
Date = "`[" + row[2] + "]`\n"
724752
else:
725-
Date = "`[" + row[2] + "]`\n"
753+
if EndDate:
754+
Date = "`" + row[2] + "`"
755+
elif SoloImporting:
756+
Date = "`" + row[2] + " " + row[1] + ":`\n"
757+
else:
758+
Date = "`" + row[2] + "`\n"
726759
Message = row[3]
727760

728761
if NoTimestamps:

0 commit comments

Comments
 (0)