检测QQ在线状态脚本(20141022测试成功)

import time,datetime    
import urllib2   
def chk_qq(qqnum):
    chkurl = 'http://wpa.paipai.com/pa?p=1:'+`qqnum`+':17'
    a = urllib2.urlopen(chkurl)    
    length=a.headers.get("content-length")    
    a.close()    
    print datetime.datetime.now() 
    print length   
    if length=='2348':    
        return 'Online'   
    elif length=='2205':    
        return 'Offline'   
    else:    
        return 'Unknown Status!'  
def writestate(statenow):
    f=open(str(qq),'a')
    m=str(datetime.datetime.now())+"===state===="+statenow+"\n\r"
    f.write(m)
    f.close()

qq = 12345678
##state=1
if __name__=='__main__':

    while 1:
        stat = chk_qq(qq)
        writestate(stat)
        time.sleep(6000) ##5分钟测一次
        print `qq` + ' is ' + stat

  

posted @ 2014-10-22 16:53  小五义  阅读(4019)  评论(8编辑  收藏  举报