diff --git a/README.md b/README.md index 687aeb6..14ebf4b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# epvpn_xml2vcard -For EPVPN: Takes the XML file and generates a vCard (makes sense for Android and stuff) +# epvpn\_xml2vcard +For [EPVPN](https://www.eventphone.de): Takes the XML file you've downloaded before and generates a vCard (makes sense for Android and stuff). diff --git a/epvpn_xml2vcard b/epvpn_xml2vcard new file mode 100755 index 0000000..fc4abf3 --- /dev/null +++ b/epvpn_xml2vcard @@ -0,0 +1,73 @@ +#!/usr/bin/python3 +# Author: Bandie Canis +# License: BSD-2-clause + +import xml.etree.ElementTree as ET +import getopt, sys +import os.path + +def main(argv): + + infile = '' + outfile = '' + + try: + opts, args = getopt.getopt(argv, "hi:o:", ["if=","of="]) + except getopt.GetoptError as err: + print(err) + helpMsg(sys.argv[0]) + sys.exit(1) + + for opt, arg in opts: + if opt == '-h': + helpMsg(sys.argv[0]) + sys.exit(0) + elif opt in ('-i', '--if'): + infile = arg + elif opt in ('-o', '--of'): + outfile = arg + + if(infile == '' or outfile == ''): + helpMsg(sys.argv[0]) + sys.exit(1) + + if not(os.path.isfile(infile)): + print("Error: ", infile, "doesn't exist.") + sys.exit(1) + + + doEet(infile, outfile) + + +def doEet(infile, outfile): + + + root = ET.parse(infile).getroot().find('entries') + + + f = open(outfile, 'w') + counter = 0 + for c in root.findall('entry'): + counter+=1 + tel = c.find('extension').text + name = c.find('name').text + loc = c.find('location').text + + entry = "BEGIN:vCard\nVERSION:3.0\nN:{}\nTEL;type=voice:{}\nCATEGORIES:EPVPN\nNOTE:Location: {}\nEND:vCard\n\n".format(name, tel, loc) + + f.write(entry) + + f.close() + print("Contacts processed:", counter) + print("Have fun! :)") + + + + +def helpMsg(progname): + print(progname, "-i -o ") + + + +if __name__ == "__main__": + main(sys.argv[1:])