qq空间代码(爱玩QQ空间的看过来,十分钟写几行python代码实现记录条说说详情)
python程序记录QQ空间条说说的访问详情这是腾讯先生通过特殊的算法记录阅读该条说说的好友的,这段脚本就是用来记录一条说说的访问者,并保存到文件中。执行main.py,输入相应的号码就可以记录。实在是追踪情敌,发现暗恋者的必备良器。
编码可能有问题,如果有BUG请自行改正。
#!python
# coding=utf-8
import qqlib, getpass, json, time, sys, codecs
reload(sys)
sys.setdefaultencoding(sys.stdin.encoding)
visitor=[]
fp=codecs.open('visitors.log','a',sys.stdin.encoding)
def ut2t(uttime):
#unix time to date
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(float(uttime)))
def getjson(str):
str=str.replace('_Callback(','')
str=str.replace(');','')
re=json.loads(str)
return re
def justdoit():
jsonstr=qq.getblogvisit(blogid,vqqid)
jsondate=getjson(jsonstr)
for i in range(0,len(jsondate['data']['list'])):
if jsondate['data']['list'][i]==None:
break
vuin=jsondate['data']['list'][i]['uin']
vname=jsondate['data']['list'][i]['name']
vtime=jsondate['data']['list'][i]['time']
flag=False
for visi in visitor:
if(visi['uin']==vuin and visi['time']==vtime):
flag=True
break
if flag:
continue
visitoradd={'name':vname,'uin':vuin,'time':vtime}
visitor.append(visitoradd)
fp.write('\n'+str(vname.decode(sys.stdin.encoding))+'\t\t\t\t\t'+str(vuin)+'\t\t\t\t\t'+str(ut2t(float(vtime))))
return jsondate['data']['viewCount']
qqid=raw_input("QQ number:")
qqpaswd = getpass.getpass('QQ password:')
blogidstr=raw_input("blog number(blog number,qq number):")
blogidspl=blogidstr.split(',')
blogid=blogidspl[0]
vqqid=None
if(len(blogidspl)>1):
vqqid=blogidspl[1]
timepause=int(raw_input('Pause(seconds, at last 15s):'))
if timepause<15:
timepause=15
qq=qqlib.QQ(qqid,qqpaswd)
qq.login()
print 'login success!'
while True:
print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())+', '+str(justdoit())+' peoples.\n'
time.sleep(timepause)
fp.close()