Suradnik:4ndY/gammu2android.py
Izvor: HrOpenWiki
from lxml import etree as ET import sys import time input_file = sys.argv[1] output_file = sys.argv[2] tree = ET.parse( input_file ) output = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" output += "<?xml-stylesheet type=\"text/xsl\" href=\"sms.xsl\"?>" count = str(len( tree.findall( "message" ) )) output += "<smses count=\""+count+"\">" for msg in tree.iterfind( "message" ): output += "<sms protocol=\"0\" " for element in msg: if element.tag == "telephone": output += "address=\"" + element.text + "\" " if element.tag == "date": output += "readable_date=\"" + element.text + "\" " if element.tag == "text": output += "body=\"" + element.text + "\" " if element.tag == "dateenc": unixtime = int( time.mktime( time.strptime(element.text, "20%y%m%d%H%M%S") ) ) output += "date=\"" + str(unixtime) + "000\" " if element.tag == "stat": if element.text == "Sent": ttype = "2" else: ttype = "1" output += " type=\"" + ttype + "\" subject=\"null\" toa=\"null\" sc_toa=\"null\" service_center=\"null\" read=\"1\" status=\"-1\" />" + "\n" output += "</smses>" # write output to file f = open( output_file, 'w' ) f.write( output.encode('utf-8') ) f.close()