[Python-modules-commits] [python-coloredlogs] 06/07: Add csv2vcf and example contacts.csv

Gaurav Juvekar gauravjuvekar-guest at moszumanska.debian.org
Sun Mar 12 20:19:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

gauravjuvekar-guest pushed a commit to branch master
in repository python-coloredlogs.

commit 39ad2d9776d5288501cd0c51b604f0f634f72b96
Author: Gaurav Juvekar <gauravjuvekar at gmail.com>
Date:   Sun Jan 22 22:19:05 2017 +0530

    Add csv2vcf and example contacts.csv
---
 shell_programming/contacts.csv |  2 ++
 shell_programming/csv2vcf.sh   | 47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/shell_programming/contacts.csv b/shell_programming/contacts.csv
new file mode 100644
index 0000000..c0c967a
--- /dev/null
+++ b/shell_programming/contacts.csv
@@ -0,0 +1,2 @@
+"FULLNAME","FNAME","MNAME","LNAME","EMAIL","PHONE"
+"A B C","A","B","C","abc at d.mail","+12 34567893"
diff --git a/shell_programming/csv2vcf.sh b/shell_programming/csv2vcf.sh
new file mode 100755
index 0000000..dafa43b
--- /dev/null
+++ b/shell_programming/csv2vcf.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# Following fields in the CSV are supported
+# FULLNAME, {F,M,L}NAME (first,middle,last), EMAIL, PHONE
+# These must be named EXACTLY in the first (header) row of the CSV
+# Double quotes in the CSV are stripped.
+# Output is in the form of multiple files named contact_0.vcf, etc
+
+# set -e
+# set -x
+
+IFS=,
+read header
+fields=$(echo "$header" | tr -d '"')
+
+i=0
+# header_index contains the index of the record corresponding to a named field
+declare -A header_index
+for field in $fields
+do
+	header_index[$field]=$i
+	i=$(($i + 1))
+done
+
+i=0
+while read line
+do
+
+	fields=$(echo "$line" | tr -d '"')
+	fields=($fields)
+	fullname=${fields[${header_index[FULLNAME]}]}
+	fname=${fields[${header_index[FNAME]}]}
+	mname=${fields[${header_index[MNAME]}]}
+	lname=${fields[${header_index[LNAME]}]}
+	email=${fields[${header_index[EMAIL]}]}
+	phone=${fields[${header_index[PHONE]}]}
+
+	cat > "contact_$i.vcf" <<END_CAT
+BEGIN:VCARD
+VERSION:3.0
+N:${lname};${mname};${fname}
+FN:${fullname}
+TEL;TYPE=WORK,VOICE:${phone}
+EMAIL:${email}
+END:VCARD
+END_CAT
+	i=$(($i + 1))
+done

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-coloredlogs.git



More information about the Python-modules-commits mailing list