contacts: add example CSV and eet generator.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 10 Aug 2012 20:58:48 +0000 (17:58 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 10 Aug 2012 20:58:48 +0000 (17:58 -0300)
Simple script to get a CSV and generate the EET. It should be easy to
have most addressbooks to generate this, or use OpenOffice to do so.

Makefile.am
data/examples/contacts.csv [new file with mode: 0644]
data/scripts/ofono-efl-contacts-db-create.py [new file with mode: 0755]

index c4cdc1d..d5bd2d5 100644 (file)
@@ -130,3 +130,13 @@ data/themes/default-sd.edj: $(top_builddir)/Makefile $(top_srcdir)/data/themes/d
 clean-local:
        rm -f $(top_builddir)/data/themes/default.edj
        rm -f $(top_builddir)/data/themes/default-sd.edj
+
+examplesdir = $(pkgdatadir)/examples
+examples_DATA = \
+data/examples/contacts.csv
+
+scriptsdir = $(pkgdatadir)/scripts
+scripts_SCRIPTS = \
+data/scripts/ofono-efl-contacts-db-create.py
+
+EXTRA_DIST += $(examples_DATA) $(scripts_SCRIPTS)
diff --git a/data/examples/contacts.csv b/data/examples/contacts.csv
new file mode 100644 (file)
index 0000000..b220993
--- /dev/null
@@ -0,0 +1,2 @@
+John, Smith, 11 2222-3333, 11 2222-4444, 11 9999-8888
+Paul, Cooper, 22 2222-2222, 22 2222-3333, 22 9999-9999
diff --git a/data/scripts/ofono-efl-contacts-db-create.py b/data/scripts/ofono-efl-contacts-db-create.py
new file mode 100755 (executable)
index 0000000..22dc610
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+import sys, csv, os, os.path, re
+
+if len(sys.argv) < 2:
+    print "Converts a CSV file to ofono-efl contacts database."
+    print
+    print "CSV file should have the following columns:"
+    print "\t - first name"
+    print "\t - last name"
+    print "\t - work phone"
+    print "\t - home phone"
+    print "\t - mobile phone"
+    raise SystemExit("missing input CSV file")
+
+reader = csv.reader(open(sys.argv[1], 'rb'))
+
+tmp = os.tmpnam()
+tmpfile = open(tmp, 'wb')
+
+tmpfile.write("""\
+group "Contacts_List" struct {
+    group "list" list {
+""")
+
+cleannumber = re.compile("[^0-9]")
+
+for row in reader:
+    first, last, work, home, mobile = row
+
+    first = first.strip()
+    last = last.strip()
+
+    work = cleannumber.sub('', work)
+    home = cleannumber.sub('', home)
+    mobile = cleannumber.sub('', mobile)
+
+    print "Add: %s, %s, %s, %s, %s" % (first, last, work, home, mobile)
+
+    tmpfile.write("""
+        group "Contact_Info" struct {
+            value "picture" string: "";
+            value "work" string: "%(work)s";
+            value "home" string: "%(home)s";
+            value "mobile" string: "%(mobile)s";
+            value "name" string: "%(first)s";
+            value "last_name" string: "%(last)s";
+        }
+""" % {"first": first, "last": last,
+       "work": work, "home": home, "mobile": mobile})
+
+tmpfile.close()
+
+dbfile = os.path.expanduser("~/.config/ofono-efl/contacts.eet")
+
+os.system("eet -e '%s' contacts '%s' 1" % (dbfile, tmp))
+os.unlink(tmp)
+
+print "Created %s" % (dbfile,)
+print
+print "You can decompile this database with the following command:"
+print "\teet -d %s contacts /tmp/contacts.txt" % (dbfile,)
+print
+print "Edit and then recompile it with the following command:"
+print "\teet -e %s contacts /tmp/contacts.txt" % (dbfile,)
+print