Import Google Contacts into abook for neomutt
As a part of abandoning Google services I wanted to get all my contacts collected over the years and be able to use then in neomutt.
Neomutt works well with abook contact “manager” so that was an easy choice.
How to Export Google contacts
- Go to Google Contacts.
- Check the box next to any contact and in the top left,
click Selection Actions and then All. - In the top left, click More actions and then Export.
- To back up your contacts, select Google CSV.
- To save your file, click Export.
Import to abook
Unfortunately the Google CSV is not compatible with what abook expects.
I inspected the source code
and found the most suitable input format: allcsv
.
It’s listed with
$ abook --formats
Python for the rescue
This script google2abook.py
will filter and rearrange the columns in the Google CSV file
and output the format suitable for abook conversion (allcsv
input format).
import sys
import csv
if __name__ == "__main__":
reader = csv.DictReader(sys.stdin)
writer = csv.writer(sys.stdout, delimiter=",", lineterminator="\n")
for rec in reader:
if not rec["E-mail 1 - Value"].strip():
# no email no cry
continue
# abook converter expects these columns
writer.writerow(
[
rec["Name"],
rec["E-mail 1 - Value"],
rec["Address 1 - Formatted"],
"", # address 2
rec["Address 1 - City"],
"", # state
rec["Address 1 - Postal Code"],
rec["Address 1 - Country"],
rec["Phone 2 - Value"],
rec["Phone 3 - Value"], # guess
"", # fax
rec["Phone 1 - Value"], # mobile - guess
rec["Nickname"],
rec["Website 1 - Value"],
rec["Notes"],
rec["Birthday"],
]
)
Putting it together
So let’s take the Google exported file google-contacts.csv
and
create an abook address book.
cat google-contacts.csv | python3 csv2abookcsv.py > abook-contacts.csv
abook --convert --informat allcsv --infile abook-contacts.csv \
--outformat abook --outfile address.abook
Then you need to put the output file into $HOME/.abook/addressbook
and voìla!
published: 2023-05-01
last modified: 2023-05-01
https://vit.baisa.cz/notes/code/google-to-abook/
last modified: 2023-05-01
https://vit.baisa.cz/notes/code/google-to-abook/