|
2 | 2 | import shutil |
3 | 3 | import sqlite3 |
4 | 4 | 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 |
5 | 29 |
|
6 | 30 | conn = sqlite3.connect('msgstore.db') |
7 | 31 | path_to_media = "Media/" |
|
68 | 92 | pass |
69 | 93 |
|
70 | 94 | 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') |
71 | 101 | try: |
72 | | - os.mkdir(os.path.join(path_to_media, "sorted", person[1])) |
| 102 | + os.mkdir(os.path.join(path_to_media, "sorted", name)) |
73 | 103 | except OSError as e: |
74 | 104 | # print ("Creation of the directory failed \n {}".format(e.strerror)) |
75 | 105 | pass |
|
82 | 112 | is_file = os.path.isfile(path_to_file) |
83 | 113 | if is_file: |
84 | 114 | 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)) |
86 | 116 | # print("{} copied in {}".format(image, person[1])) |
87 | 117 | except: |
88 | 118 | print ("Copy failed for {}".format(image)) |
|
98 | 128 | is_file = os.path.isfile(path_to_file) |
99 | 129 | if is_file: |
100 | 130 | 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)) |
102 | 132 | # print("{} copied in {}".format(video, person[1])) |
103 | 133 | except: |
104 | 134 | print ("Copy failed for {}".format(video)) |
|
0 commit comments