After exporting all the contacts with Export Telegram data, I created a Python script that extracted all the contacts from the generated website.
The script, positioned directly inside the Telegram Desktop folder, is the following:
#FIRST FOLDER TO CHANGE
pathToFile = 'DataExport_08_12_2018 (2)/lists/contacts.html'
with open(pathToFile, encoding='utf-8') as f:
lines = tuple(l for l in f.readlines())
with open('csvToConvert.csv', "w", encoding="utf-8") as outputFile:
outputFile.write('nome, telefono\n')
for i,l in enumerate(lines):
if l.startswith(' <div class="name bold">') and lines[i+4].startswith(' <div class="details_entry details">'):
tel = lines[i+5].replace(' ','')
if not tel.startswith('+39'):
if "+" in tel and tel[1] == '3':
outputFile.write(lines[i+1].replace('\n','') + ', ' + tel.replace('+', '+39'))
else:
if tel[0] == '0':
outputFile.write(lines[i+1].replace('\n','') + ', ' + tel)
elif tel.startswith('0039'):
outputFile.write(lines[i+1].replace('\n','') + ', ' + tel)
else:
outputFile.write(lines[i+1].replace('\n','') + ', ' + tel)
Note that this script is aimed to the Italian telephone numbers (note the prefixes that are checked in some if clauses)!
However, once the folder is modified and the script is executed, a file called csvToConvert.csv is generated.
Subsequently, this file must be passed to a program called CVS to VCard, which takes care of converting the csv file into a vcard file.
Then, once the vcard file is generated, just enter it on google contacts (https://contacts.google.com/ > more > import), and you're done! Magically you will find all the contacts in the phone book of your android phone!
I hope I have been helpful.