Skip to content

Commit 07312b4

Browse files
committed
init version, works
1 parent bf55ed2 commit 07312b4

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

do.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import sqlite3
2+
import os
3+
import shutil
4+
5+
conn = sqlite3.connect('msgstore.db')
6+
path_to_media = "wa_img/"
7+
8+
cursor = conn.execute('''
9+
select raw_string
10+
from jid
11+
where server = "s.whatsapp.net"
12+
''')
13+
14+
people = []
15+
16+
for row in cursor:
17+
people.append(row[0])
18+
19+
population = len(people)
20+
21+
for person in enumerate(people):
22+
cursor = conn.execute('''
23+
select
24+
25+
_id,
26+
media_mime_type,
27+
substr(
28+
substr(thumb_image,instr(thumb_image,'IMG'),60)
29+
,instr(substr(thumb_image,instr(thumb_image,'IMG'),23),'IMG')
30+
,23)
31+
from `messages`
32+
where
33+
`key_remote_jid` like '%{}%'
34+
and `media_mime_type` like '%image%';
35+
'''.format(person[1]))
36+
37+
media = []
38+
for row in cursor:
39+
try:
40+
media.append(row[2].decode('ascii'))
41+
except:
42+
pass
43+
44+
try:
45+
os.mkdir(os.path.join(path_to_media, person[1]))
46+
except OSError:
47+
print ("Creation of the directory failed")
48+
49+
for file in media:
50+
path_to_file = os.path.join(path_to_media, file)
51+
print("Debug: path is {}".format(path_to_file))
52+
53+
try:
54+
does_file_exist = os.path.isfile(path_to_file)
55+
except:
56+
pass
57+
if does_file_exist:
58+
try:
59+
shutil.copyfile(path_to_file, os.path.join(path_to_media, person[1], file))
60+
except:
61+
print ("Copy failed for {}".format(file))
62+
print("{} of {} complete".format(person[0], population))
63+
64+
conn.close()

0 commit comments

Comments
 (0)