Skip to content

Instantly share code, notes, and snippets.

@yrcjaya
Created May 14, 2021 06:08
Show Gist options
  • Save yrcjaya/d48d14879245fe8c69d4d2e77b7a8933 to your computer and use it in GitHub Desktop.
Save yrcjaya/d48d14879245fe8c69d4d2e77b7a8933 to your computer and use it in GitHub Desktop.
Convert simple CSV to Google Contacts Fields CSV
#!/bin/env python3
import typer # pip install typer==0.3.2
import csv
COLS = '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,Phone 1 - Type,Phone 1 - Value'.split(',')
app = typer.Typer()
@app.command()
def columns(
silent: bool = typer.Option(False, help="Output only column names.")
):
'''List CSV Columns'''
if not silent:
typer.echo()
typer.secho('Columns Orderd in CSV', underline=True, bold=True)
typer.echo()
for col in COLS:
typer.echo(col)
@app.command()
def convert(
source: typer.FileText,
destination: typer.FileTextWrite):
reader = csv.DictReader(source, delimiter=',')
writer = csv.DictWriter(destination, fieldnames=COLS)
writer.writeheader()
for row in reader:
writer.writerow({
'Name': row['Name'],
'Phone 1 - Type': 'Mobile',
'Phone 1 - Value': row['Cel']})
raise typer.Exit()
if __name__ == '__main__':
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment