Razlika između inačica stranice Suradnik:4ndY/gammu2android.py
Izvor: HrOpenWiki
m |
m |
||
Redak 8: | Redak 8: | ||
# date: 12. 2011. | # date: 12. 2011. | ||
# contact: andrej@dundovic.com.hr | # contact: andrej@dundovic.com.hr | ||
+ | # licence: GPLv3 | ||
from lxml import etree as ET | from lxml import etree as ET |
Trenutačna izmjena od 17:45, 15. prosinca 2011.
Ova skripta namijenjena je prebacivanju SMS poruka s bilo kojeg mobitela kompatibilnog s programom Wammu/Gammu na uređaj s Androidom. Skripta pretvara XML datoteku s porukama koju stvori Wammu prilikom izvoza poruka u XML format kompatibilan s aplikacijom SMSBackupRestore pomoću koje se onda može uvesti na Android.
#!/usr/bin/python # -*- coding: utf-8 -*- # author: Andrej Dundovic # date: 12. 2011. # contact: andrej@dundovic.com.hr # licence: GPLv3 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()