您的位置:首页 > 其它

2700c 短信 临时保存

2012-05-25 17:54 134 查看
# -*- coding: utf-8 -*-

class MyMsg:
"It's used to save the 2700c msg"
phonePath = "c:/phone.txt"
msgPath = "c:/msg.txt"
outPath = "c:/"
phones = {}

@staticmethod
def parsePhone():
f = open(MyMsg.phonePath, "r")
for line in f.readlines():
c = line[0:-1].split("\t")
MyMsg.phones[c[1]] = c[0]  #delete the last '\n'
f.close()

@staticmethod
def checkNum(n):
if(n.startswith("+86")):
n = n[3:len(n)]
if(n.startswith("12520")):
n = n[5:len(n)]
return n

@staticmethod
def parseMsg():
MyMsg.parsePhone()
f = open(MyMsg.msgPath, "r")
file = open(MyMsg.outPath + "out.txt", "w")
fno = open(MyMsg.outPath + "who.txt", "w")
line = f.readline()
while line:
lens = len(line)
while line and line[-2] != "\"":
nline = f.readline()
line = line[0:-1] + ' '
line += nline
else:
if line == 0:
break
tp = line[7:11]
if tp == "READ":
tp = "RECE"
else:
tp = "SEND"
s = line.find("\"", 7, lens)
s = line.find("\"", s+1, lens)
num = None
if tp == "RECE":
e = line.find("\"", s+1, lens)
num = line[s+1 : e]
s = e+1
for z in range(5):
s = line.find("\"", s+1, lens)
e = line.find("\"", s+1, lens)
else:
s = line.find("\"", s+1, lens)
s = line.find("\"", s+1, lens)
e = line.find("\"", s+1, lens)
num = line[s+1 : e]
s = e+1
for z in range(3):
s = line.find("\"", s+1, lens)
e = line.find("\"", s+1, lens)
tm = line[s+1 : e]
s = e+1
for z in range(3):
s = line.find("\"", s+1, lens)
con = line[s+1 : -2]
n = MyMsg.checkNum(num)

if n in MyMsg.phones:
n = MyMsg.phones

file.write(tp)
file.write('|' + n + '|' + tm + '|')
file.write(con)
file.write('\n')
else:
fno.write(tp)
fno.write('|' + n + '|' + tm + '|')
fno.write(con)
fno.write('\n')
line = f.readline()
f.close()
file.close()
fno.close()
print "瑙f瀽瀹屾瘯锛?

MyMsg.parseMsg()

##f = open("c:/msg.txt", "r");
##
##a = [line for line in f.readlines()]
##
##i = a[0]

##print i, len(i)
##ca = i.rfind("\"")
##cb = i.rfind("\"", 0, ca)
##print ca, cb, i[cb+1:ca]

##print i[7:11] == "READ"

##sa = -1
##for k in range(5):
##    sa = i.find("\"", sa+1, len(i))
##sa += 1
##sb = i.find("\"", sa, len(i))
##print i[sa : sb]
##for k in range(5):
##    sb = i.find("\"", sb+1, len(i))
##sa = sb+1
##print i[sa: i.find("\"", sa, len(i))]
##
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: