查看文章 |
怎么在OS X上方便地看iPhone上的短信?
2009-03-05 20:16
目前的方法好像不多: 1. 你可以把短信数据库文件sms.db拷出来然后用桌面程序,像FireFox的免费插件 SQLite Manager来看,这个很方便,还能做一些有趣的小统计,就是有点丑。 2. 似乎有个PhoneView之类的程序,但是它的速度实在是很慢,几乎不能用。 本来想写一个可以和Contacts数据库结合的看短信的小程序,后来看到Adium的查看历史记录的功能做得不错,于是考虑将sms.db里的东西导出为Adium能够识别的聊天记录,就是用Adium来看你的短信记录了,像下面这张图这样: (下面这张图正好记录了我被移动坑害的全过程) ![]() 从短信数据库到Adium Chat Log的转换需要由一个Python脚本完成, 因为可选的参数实在太多,写死了很多东西,所以这类程序最好还是写成GUI的,当然自己用用写个Script绝对是足够了。 (注意iPhone的短信数据库内的时间字段要加上时差校正,我们在东八区所以时间都要加上8小时) 转一个4200条短信的对话大约0.4s吧, 每个聊天都是以天来分割的。 #!/usr/bin/env pyt # encoding: utf-8 import sqlite3 import time import xml.sax.saxutils import os # time deviation delta_t = 8 * 3600 # target cell phone number cellphone_num = '%' + '10086' # tag assigning to the conversation list tagging = 'chinamobile@cm.com' # what should the other contact be called? name_other = 'China Mobile' # who am I again? name_self = 'Me' def main(): """produce Adium Chat Log from SMS.db""" print 'starting.......' conn = sqlite3.connect('SMS/sms.db') cur = conn.cursor() #flags == 3 mine #flags == 2 as the address specifies #starting date 1206241522 time formats 2008-10-12T15:19:06+08:00 cur.execute('select text,flags,date from message where address like "%s"' % cellphone_num) items = cur.fetchall() start_time = 1213632000 + delta_t # a starting time tinterval = 86400 # a day t = start_time dayinit = '' dayinittup = () dayoutput = '' strb = [] #composing buffer items = [(item[0],item[1],int(item[2]) + delta_t) for item in items] items.append(("****","5",1513632000.0)) #add an fake end marker for item in items: #print int(item[2]) if(int(item[2]) >= t + 86400 or item[2] == "5"): #start a new file new file for one day if(len(strb) == 0): #no sms for today print 'no sms for today' dayinit = '' t += 86400 while int(item[2]) >= t + 86400: t+= 86400 else: mheader = '<?xml version="1.0" encoding="UTF-8" ?>\n<chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="My Cell Phone" service="MSN"><event type="windowOpened" sender="overboming@live.cn" time="%s"/>' % dayoutput message_body = "".join(i for i in strb) mtail = '<event type="windowClosed" sender="overboming@live.cn" time="%s"/>\n</chat>' % dayinit #print mheader #print message_body #print mtail print 'out put for conversation at %s' % dayinit foldertime = dayinit[0:dayinit.find('T')] + dayinit[dayinit.find('T'):dayinit.find('+')].replace(':','.') + "+0800" foldername = "%s(%s).chatlog" % (tagging,foldertime) if not os.path.exists('Output/%s' % foldername): os.makedirs('Output/%s' % foldername) open('Output/%s/%s(%s).xml' % (foldername,tagging,foldertime),'w').write((mheader + message_body.encode('utf-8') + mtail)) dayinit = '' strb = [] t += 86400 while int(item[2]) >= t + 86400: t+= 86400 if(int(item[2]) > t and int(item[2]) < t + 86400): tt = time.gmtime(item[2]) tstr = "%d-%2d-%2dT%2d:%2d:%2d+08:00" % (tt[0],tt[1],tt[2],tt[3],tt[4],tt[5]) tstr = tstr.replace(' ','0') dayinit = (len(dayinit) == 0) and tstr or dayinit dayoutput = tstr if(int(item[1]) == 2): strb.append('<message sender="" time="%s" alias="%s"><div><span style="color: #000000; font-family: Helvetica; font-size: 12pt;">%s</span></div></message>\n' % (tstr,name_other,(xml.sax.saxutils.escape(item[0])))) else: strb.append('<message sender="" time="%s" alias="%s"><div><span style="font-family: Helvetica; font-size: 12pt;">%s</span></div></message>\n' % (tstr,name_self,(xml.sax.saxutils.escape(item[0])))) print "converted %s messages" % (len(items)) print strb cur.close() conn.close() main() |
