eud2gc.py 1.6 KB

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