update donations URI
[claws.git] / tools / eud2gc.py
blob5794e3b0050926832c2a436920e5a865ae6d4069
1 #!/usr/bin/env python3
3 import string, sys
6 def lReadEfile(sFileName):
7 try:
8 sLines = open(sFileName).read()
9 except:
10 print ('Error opening %s' %sFileName)
11 lLines = []
12 lLines = sLines.split('\n')
13 return lLines
16 def dElines2Dict(lElines):
17 dAliases = {}
18 for sEntry in lElines:
19 if '"' in sEntry:
20 lChunks = sEntry.split('"')
21 else:
22 lChunks = sEntry.split(' ')
23 if lChunks[0] != 'alias':
24 print ('ignoring invalid line: %s' %sEntry)
25 else:
26 sAdresses = lChunks[2:].join(',')
27 print ('Entry added: %s %s' %(lChunks[1],sEntry))
28 dAliases[lChunks[1]]=sAdresses
29 return dAliases
32 def vWriteGfile(dAliases, sFileName):
33 try:
34 oFile = open(sFileName, 'w')
35 except:
36 print ('Error opening %s' %sFileName)
37 return 0
38 for sKey in dAliases.keys():
39 #print ('BEGIN:VCARD')
40 #print ('N:;%s' %sKey)
41 #print ('BDAY:')
42 #print ('ADR;HOME:;;;;;;')
43 #print ('TEL:;')
44 #print ('EMAIL;INTERNET:%s' %dAliases[sKey])
45 #print ('END:VCARD')
46 oFile.write ('BEGIN:VCARD\n')
47 oFile.write ('FN:%s\n' %sKey)
48 oFile.write ('N:;%s\n' %sKey)
49 oFile.write ('BDAY:\n')
50 oFile.write ('ADR;HOME:;;;;;;;\n')
51 oFile.write ('TEL:;\n')
52 oFile.write ('EMAIL;INTERNET:%s\n' %dAliases[sKey])
53 oFile.write ('END:VCARD\n')
54 oFile.close()
55 return 1
58 if __name__ == '__main__':
59 if len(sys.argv) >= 3:
60 sEfileName = sys.argv[1]
61 sGfileName = sys.argv[2]
62 lAliases = lReadEfile(sEfileName)
63 dAliases = dElines2Dict(lAliases)
64 if vWriteGfile(dAliases, sGfileName) == 1:
65 print ('Done!')
66 else:
67 print ('Error saving output-file')
68 else:
69 print ('Usage:\n %s <Eudora addressbook> <Gnomecard file>' %sys.argv[0])