Created
February 24, 2013 19:33
-
-
Save NewProggie/5025191 to your computer and use it in GitHub Desktop.
create fritzbox compatible xml file from csv contacts file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin env python | |
# -*- coding: utf-8 -*- | |
from lxml import etree as et | |
def main(): | |
mpa = dict.fromkeys(range(32)) | |
phonebooks = et.Element('phonebooks') | |
phonebook = et.SubElement(phonebooks, "phonebook") | |
for line in open('kontakte.csv', 'r').read().split('\r'): | |
name, num1, num2 = map(lambda x:str(x), line.split(';')) | |
contact = et.SubElement(phonebook, "contact") | |
category = et.SubElement(contact, "category").text = "1" | |
person = et.SubElement(contact, "person") | |
realName = et.SubElement(person, "realName").text = name | |
imageURL = et.SubElement(person, "imageURL") | |
telephony = et.SubElement(contact, "telephony") | |
number1 = et.SubElement(telephony, "number", type="home", vanity="", prio="1651340622").text = num1 | |
if len(num2) > 0: | |
number2 = et.SubElement(telephony, "number", type="mobile", vanity="", prio="1").text = num2 | |
services = et.SubElement(contact, "services") | |
setup = et.SubElement(contact, "setup") | |
print et.tostring(phonebooks, pretty_print=True, encoding="iso-8859-1", xml_declaration=True) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment