Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@janoamaral
Last active April 7, 2020 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janoamaral/30b3dac7961609715872e8c065406de3 to your computer and use it in GitHub Desktop.
Save janoamaral/30b3dac7961609715872e8c065406de3 to your computer and use it in GitHub Desktop.
Convert exported Excel CSV to Google Contacts CSV
#!/usr/bin/env python3
"""
Module Docstring
"""
__author__ = "Alejandro Amaral"
__version__ = "0.0.1"
__license__ = "MIT"
import os, sys
def main():
""" Main entry point of the app """
with os.scandir('DIRECTORY') as entries:
file1 = open(os.path.dirname(sys.argv[0]) + '\\OUTPUT.CSV', 'w', encoding='utf-8')
file1.write('Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Language,Photo,Group Membership,E-mail 1 - Type,E-mail 1 - Value,E-mail 2 - Type,E-mail 2 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value,Phone 3 - Type,Phone 3 - Value,Address 1 - Type,Address 1 - Formatted,Address 1 - Street,Address 1 - City,Address 1 - PO Box,Address 1 - Region,Address 1 - Postal Code,Address 1 - Country,Address 1 - Extended Address\n')
for i, entry in enumerate(entries):
with open('...' + entry.name, 'r', encoding='utf-8') as f:
data = f.readlines()
for line in data:
nombreCompleto = line.split('\t')[1]
hijo = line.split('\t')[0]
tel = line.split('\t')[2]
mail = line.split('\t')[3].replace('\n\r','').rstrip()
grupo = entry.name.replace('.tsv','')
if len(nombreCompleto.split(',')) > 1:
nombre = nombreCompleto.split(',')[1].strip()
apellido = nombreCompleto.split(',')[0].strip()
nombreCompleto = nombreCompleto.replace(',', ' ')
file1.write(f"{nombreCompleto},{nombre},,{apellido},,,,,,,,,,,,,,,,,,,,,,{hijo.replace(',','')},,,* ALUMNOS {grupo},* Other,{mail},Other,{mail},Work,{tel},Mobile,,Other,,,,,,,,,,\n")
else:
file1.write(f"{nombreCompleto},{nombreCompleto},,,,,,,,,,,,,,,,,,,,,,,,{hijo.replace(',','')},,,* ALUMNOS {grupo},* Other,{mail},Other,{mail},Work,{tel},Mobile,,Other,,,,,,,,,,\n")
file1.close()
if __name__ == "__main__":
""" This is executed when run from the command line """
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment