Razlika između inačica stranice Suradnik:4ndY/gammu2android.py

Izvor: HrOpenWiki
Skoči na: orijentacija, traži
m (Nova stranica: <pre> 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='…)
 
m
 
Nisu prikazane 3 međuinačice istog suradnika
Redak 1: Redak 1:
 +
Ova skripta namijenjena je prebacivanju SMS poruka s bilo kojeg mobitela kompatibilnog s programom [[Wammu]]/Gammu na uređaj s [[Android]]om. Skripta pretvara XML datoteku s porukama koju stvori Wammu prilikom izvoza poruka u XML format kompatibilan s aplikacijom [http://android.riteshsahu.com/apps/sms-backup-restore SMSBackupRestore] pomoću koje se onda može uvesti na Android.
  
 
<pre>
 
<pre>
 +
#!/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
 
from lxml import etree as ET
 
import sys
 
import sys
Redak 42: Redak 51:
 
f.write( output.encode('utf-8') )
 
f.write( output.encode('utf-8') )
 
f.close()
 
f.close()
 
  
 
</pre>
 
</pre>

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()