]> piware.de Git - bin.git/blobdiff - vcard2gnokii
rewrite backup script in shell and with fixed weekly/monthly logic
[bin.git] / vcard2gnokii
index 9b40a87b0624c8d96f1ee77ff0186b8dc9a61973..f3cef82ccf258d50f1a8d1b111b44c636278d083 100755 (executable)
@@ -2,7 +2,7 @@
 
 import sys
 
-def output_info(info):
+def output_info(info, pos):
     if info.has_key('X-EVOLUTION-FILE-AS'):
        result = info['X-EVOLUTION-FILE-AS']
     elif info.has_key('N'):
@@ -12,30 +12,38 @@ def output_info(info):
        print >> sys.stderr, 'No suitable name for', info
        return
 
-    result += ';;ME;;5'
+    result += ';;ME;%i;5' % pos
+
+    id = 0
 
     for k, v in info.iteritems():
        kf = k.split(';')
        type = 0
        if len(kf) > 1:
-           if kf[1] == 'TYPE=HOME':
+           if 'TYPE=HOME' in k:
                type = 2
-           elif kf[1] == 'TYPE=CELL':
+           elif 'TYPE=CELL' in k:
                type = 3
-           elif kf[1] == 'TYPE=WORK':
+           elif 'TYPE=WORK' in k:
                type = 6
 
        if kf[0] == 'ADR':
-           result += ';9;%i;9;%s' % (type, '\\n'.join([f for f in v.split(';') if f]))
-       if kf[0] == 'EMAIL':
-           result += ';8;%i;8;%s' % (type, v)
-       if kf[0] == 'TEL':
-           result += ';11;%i;11;%s' % (type, v)
-       if kf[0] == 'BDAY':
-           result += ';10;0;10;BDAY: ' + v
+            # current gnokii does not swallow type "9" (postal address)
+           result += ';10;0;%i;%s' % (id, '\\n'.join([f for f in v.split(';') if f]))
+       elif kf[0] == 'EMAIL':
+           result += ';8;%i;%i;%s' % (type, id, v)
+       elif kf[0] == 'TEL':
+           result += ';11;%i;%i;%s' % (type, id, v)
+       elif kf[0] == 'BDAY':
+           result += (';10;0;%i;BDAY: ' %id) + v
+        else:
+            continue
+
+        id += 1
 
     print result
 
+pos = 1
 info = {}
 for line in open(sys.argv[1]):
     if not line or line[0] == ' ':
@@ -53,6 +61,7 @@ for line in open(sys.argv[1]):
        if key == 'BEGIN':
            info = {}
        elif key == 'END':
-           output_info(info)
+           output_info(info, pos)
+            pos += 1
     if value:
        info[key] = value.strip()