chrrel / whatsapp-exporter

A python script for extracting WhatsApp conversations from the app's SQLite database and exporting them as HTML or txt files.
GNU General Public License v3.0
106 stars 18 forks source link

Correct column for name in wa.db #2

Closed wirmi closed 3 years ago

wirmi commented 3 years ago

display_name is the name that you see in your device when using WhatsApp :)

chrrel commented 3 years ago

Hi @wirmi, thanks for your contribution. Unfortunately, your change would not work for me. In my database, display_name only contains data when the "contact" is a group. For all other contacts the field is empty, but wa_name contains the correct data.

Does display_name also contain the names of your contacts? Is wa_name empty for you?

wirmi commented 3 years ago

Hi @chrrel! It may be different in Spain or something, but wa_name in my db is empty in almost cases (even a group), and the only column that shows everything is display_name.

Anyways, can I use your code to mix with an app I'm doing?

chrrel commented 3 years ago

Okay, thanks for the info. I'll try to check this with a second database, maybe something was changed within WhatsApp since I exported my data.

Yes! Feel free to use the code base for your project. It is all open source (license).

wirmi commented 3 years ago

Thanks Christian, you can contact me if you need something 👍

I close the pull

chrrel commented 3 years ago

My suggestion would be:

def query_contacts(db_path: str) -> Dict[str, Optional[str]]:
    contacts = {}
    con = sqlite3.connect(db_path)
    cur = con.cursor()
    for jid, wa_name, display_name in cur.execute("SELECT jid, wa_name, display_name from wa_contacts"):
        if display_name:
            contacts[jid] = display_name
        elif wa_name:
            contacts[jid] = wa_name
    con.close()
    return contacts

Using this approach we would consider both display_name and wa_name. Would this work for you, @wirmi?

chrrel commented 3 years ago

I am going to push the proposed solution in a new commit as I do not have permission for modifying the merge request.