For micropoc: Takes the XML file and generates a vCard (makes sense for Android and stuff)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

micropoc_xml2vcard 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/python3
  2. # Author: Bandie Canis
  3. # License: BSD-2-clause
  4. import xml.etree.ElementTree as ET
  5. import getopt, sys
  6. import os.path
  7. def main(argv):
  8. infile = ''
  9. outfile = ''
  10. try:
  11. opts, args = getopt.getopt(argv, "hi:o:", ["if=","of="])
  12. except getopt.GetoptError as err:
  13. print(err)
  14. helpMsg(sys.argv[0])
  15. sys.exit(1)
  16. for opt, arg in opts:
  17. if opt == '-h':
  18. helpMsg(sys.argv[0])
  19. sys.exit(0)
  20. elif opt in ('-i', '--if'):
  21. infile = arg
  22. elif opt in ('-o', '--of'):
  23. outfile = arg
  24. if(infile == '' or outfile == ''):
  25. helpMsg(sys.argv[0])
  26. sys.exit(1)
  27. if not(os.path.isfile(infile)):
  28. print("Error: ", infile, "doesn't exist.")
  29. sys.exit(1)
  30. doEet(infile, outfile)
  31. def doEet(infile, outfile):
  32. root = ET.parse(infile).getroot().find('entries')
  33. f = open(outfile, 'w')
  34. counter = 0
  35. for c in root.findall('entry'):
  36. counter+=1
  37. tel = c.find('extension').text
  38. name = c.find('name').text
  39. # loc = c.find('location').text
  40. entry = "BEGIN:vCard\nVERSION:3.0\nN:{}\nTEL;type=voice:{}\nCATEGORIES:micropoc\nEND:vCard\n\n".format(name, tel)
  41. f.write(entry)
  42. f.close()
  43. print("Contacts processed:", counter)
  44. print("Have fun! :)")
  45. def helpMsg(progname):
  46. print(progname, "-i <inputfile.xml> -o <outputfile.vcf>")
  47. if __name__ == "__main__":
  48. main(sys.argv[1:])