1

I have a fairly serious problem. I lost all the numbers in the phone book, breaking the SIM card, but luckily I saw that most of them are stored on telegram. I tried with telegram desktop to export all contacts and the operation was successful.
Now, how can I put them in the phone book? I hope there is a solution, even starting a new procedure from scratch.

Solution here does not work Sync Telegram Contact with Phone Contact

3

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.

  • You are welcome to use and contribute to the site :) – beeshyams Dec 17 '18 at 12:30
  • 1
    I'm very proud of this! Today I will do the same on Stack overflow! I have some questions to which I would like to answer! :) – Guglielmo Lischi Dec 17 '18 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.