Skip to content

Commit c42a176

Browse files
committed
added phone number to name resolver using csv export of phone contacts
1 parent b1d0171 commit c42a176

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ venv.bak/
107107
msgstore.db*
108108
Media/
109109
WhatsApp Images/
110-
WhatsApp Video/
110+
WhatsApp Video/
111+
contacts.csv

do.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22
import shutil
33
import sqlite3
44
from tqdm import tqdm
5+
import csv
6+
7+
def find_name_from_csv(phone):
8+
def get_list_of_phones(string):
9+
s = string.split(' ::: ')
10+
for i in enumerate(s):
11+
st = i[1]
12+
st = st.replace('-', '')
13+
st = st.replace(' ', '')
14+
s[i[0]] = st[-10:]
15+
return s
16+
17+
with open("contacts.csv", mode="r") as csv_file:
18+
csv_reader = csv.DictReader(csv_file)
19+
line_count = 0
20+
for row in csv_reader:
21+
if line_count == 0:
22+
line_count += 1
23+
else:
24+
for i in range(1, 6):
25+
list_of_phones = get_list_of_phones(row[f'Phone {i} - Value'])
26+
if phone in list_of_phones:
27+
return row['Given Name']
28+
line_count += 1
529

630
conn = sqlite3.connect('msgstore.db')
731
path_to_media = "Media/"
@@ -68,8 +92,14 @@
6892
pass
6993

7094
if len(images) + len(videos)> 0:
95+
try:
96+
name = find_name_from_csv(person[1].replace('@s.whatsapp.net', '').split('91')[1])
97+
except:
98+
pass
99+
if name is None:
100+
name = person[1].strip('@s.whatsapp.net')
71101
try:
72-
os.mkdir(os.path.join(path_to_media, "sorted", person[1]))
102+
os.mkdir(os.path.join(path_to_media, "sorted", name))
73103
except OSError as e:
74104
# print ("Creation of the directory failed \n {}".format(e.strerror))
75105
pass
@@ -82,7 +112,7 @@
82112
is_file = os.path.isfile(path_to_file)
83113
if is_file:
84114
try:
85-
shutil.copyfile(path_to_file, os.path.join(path_to_media, "sorted", person[1], image))
115+
shutil.copyfile(path_to_file, os.path.join(path_to_media, "sorted", name, image))
86116
# print("{} copied in {}".format(image, person[1]))
87117
except:
88118
print ("Copy failed for {}".format(image))
@@ -98,7 +128,7 @@
98128
is_file = os.path.isfile(path_to_file)
99129
if is_file:
100130
try:
101-
shutil.copyfile(path_to_file, os.path.join(path_to_media, "sorted", person[1], video))
131+
shutil.copyfile(path_to_file, os.path.join(path_to_media, "sorted", name, video))
102132
# print("{} copied in {}".format(video, person[1]))
103133
except:
104134
print ("Copy failed for {}".format(video))

0 commit comments

Comments
 (0)