Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to py 3.4 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions mmssms2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import os
import sqlite3
import sys
from Tkinter import Tk, Text, Label, Button, Frame, END
import tkFileDialog
from tkinter import Tk, Text, Label, Button, Frame, END
import tkinter.filedialog
from xml.etree import ElementTree as etree
import webbrowser
from datetime import datetime

def v(x):
xs = unicode(x)
xs = str(x)
if xs == "":
return "null"
elif x is None:
Expand All @@ -30,20 +31,20 @@ def read_messages(dbfile):
count = c.fetchone()[0]

smses = etree.Element("smses", attrib={"count": str(count)})
c.execute("SELECT _id, thread_id, address, person, date, protocol, read, priority, status, type, callback_number, reply_path_present, subject, body, service_center, failure_cause, locked, error_code, stack_type, seen, sort_index FROM sms ORDER BY date DESC")
c.execute("SELECT _id, thread_id, address, person, date, date_sent, protocol, read, status, type, reply_path_present, subject, body, service_center, locked, error_code, seen FROM sms ORDER BY date DESC")
while True:
row = c.fetchone()
if row is None: break

rec_id, thread_id, address, person, date, protocol, read, priority, status, type, callback_number, reply_path_present, subject, body, service_center, failure_cause, locked, error_code, stack_type, seen, sort_index = row
rec_id, thread_id, address, person, date, date_sent, protocol, read, status, type, reply_path_present, subject, body, service_center, locked, error_code, seen = row

if protocol is None:
protocol = 0

sms = etree.Element("sms", attrib={
"protocol": v(protocol),
"address": v(address),
"date": v(date),
"date": v(date_sent),
"type": v(type),
"subject": v(subject),
"body": v(body),
Expand All @@ -53,7 +54,7 @@ def read_messages(dbfile):
"read": v(read),
"status": v(status),
"locked": v(locked),
"readable_date": datetime.datetime.fromtimestamp(date/1000).strftime("%b %d, %Y %l:%M:%S %p"),
"readable_date": datetime.fromtimestamp(date/1000).strftime("%b %d, %Y %H:%M:%S %p"),
})
smses.append(sms)

Expand All @@ -69,8 +70,8 @@ def cli():
sys.exit(1)

messages = read_messages(args[0])
print "Read %s messages" % messages.attrib["count"]
newest = datetime.datetime.fromtimestamp(int(messages.getchildren()[0].attrib["date"])/1000)
print ("Read %s messages" % messages.attrib["count"])
newest = datetime.fromtimestamp(int(messages.getchildren()[0].attrib["date"])/1000)
if opts.output is None:
opts.output = newest.strftime("sms-%Y%m%d%H%M%S.xml")

Expand All @@ -84,15 +85,15 @@ def cli():
etree.ElementTree(messages).write(
opts.output, encoding="utf-8", xml_declaration=True)

print "Messages saved to %s." % opts.output
print "Now copy this file to your SD Card into "
print "SMSBackupRestore folder and use SMS Backup & Restore by Ritesh Sahu"
print "to restore your messages."
print "Google Play store link to the app (free version): http://goo.gl/ZO5cy"
print ("Messages saved to %s." % opts.output)
print ("Now copy this file to your SD Card into ")
print ("SMSBackupRestore folder and use SMS Backup & Restore by Ritesh Sahu")
print ("to restore your messages.")
print ("Google Play store link to the app (free version): http://goo.gl/ZO5cy")

class Gui(Frame):
def open_file(self):
filename = tkFileDialog.askopenfilename(parent=self, filetypes=[("Database Files", "*.db"),
filename = tkinter.filedialog.askopenfilename(parent=self, filetypes=[("Database Files", "*.db"),
("All files", "*.*")])
try:
os.stat(filename)
Expand All @@ -102,10 +103,10 @@ def open_file(self):
pass

def save_results(self):
newest = datetime.datetime.fromtimestamp(int(self.messages.getchildren()[0].attrib["date"])/1000)
newest = datetime.fromtimestamp(int(self.messages.getchildren()[0].attrib["date"])/1000)
output = newest.strftime("sms-%Y%m%d%H%M%S.xml")

filename = tkFileDialog.asksaveasfilename(parent=self,
filename = tkinter.filedialog.asksaveasfilename(parent=self,
filetypes=[("XML Files", "*.xml"),
("All files", "*.*")],
initialfile=output)
Expand Down