python實現查詢qq是否線上,python實現qq線上

來源:互聯網
上載者:User

python實現查詢qq是否線上,python實現qq線上

使用網址http://wpa.paipai.com/pa?p=1:' + qq + ':n,來判斷qq是否線上,其中qq為要查詢的qq號碼,n為數字1-17,選擇任何一個,其是否線上的條件不同,該程式使用n = 17,代碼如下:

#encoding:utf-8import time,datetimeimport urllib2"""該程式實現判斷QQ是否線上,QQ處於隱藏狀態也是為離線狀態,並且將檢測qq的時刻狀態記錄到檔案中"""class CheckQQ:    def __init__(self,qq=''):        self.qq = qq        self.state = ''    def check_qq(self):        check_url = 'http://wpa.paipai.com/pa?p=1:' + self.qq + ':17'        content = urllib2.urlopen(check_url)        length = content.headers.get('Content-Length')        content.close()        print datetime.datetime.now()        if length=='2348':            self.state = 'Online'             print 'Online'                  elif length=='2205':                      self.state = 'Offline'            print 'Offline'        else:            self.state = 'Other Status'            print 'Other Status'    def write2txt(self):        name = self.qq +'.txt' #檔案名稱和檔案格式        qq_file = open(name,'a')        data = str(datetime.datetime.now()) + "===state===" + self.state + "\n\r"        qq_file.write(data)        qq_file.close() if __name__=='__main__':    qq = '875588636'    qq_obj = CheckQQ(qq)    while 1:        qq_obj.check_qq()        qq_obj.write2txt()        time.sleep(60)
程式每隔60秒,會把qq狀態儲存到txt檔案中,方便查看。若需要檢測MM的qq登陸情況,可以使用該方法測試,還可以添加提醒功能,更加人性化。感謝網上分享方法的同學。


怎在python寫查詢日曆的程式 不引用模組

#!/usr/bin/evn python

def simpleCalendar():
daysOfMonth=daysOfMonths=daysOfYears=month=year=0
yearfun=lambda year:year % 400 ==0 or year % 4==0 and year % 100 !=0
print "*"*30,"calendar","*"*30
year=input("enter year: ")
leap=yearfun(year)
month=input('enter month: ')
assert month in range(1,13),"month must in 1-12"
if month==2:
daysOfMonth=29 if leap else 28
else:
daysOfMonth=30 if month in [4,6,9,11] else 31

for i in range(1,month):
if i==2:
daysOfMonths+=29 if leap else 28
else:
daysOfMonths+=30 if i in [4,6,9,11] else 31

for i in range(1900,year):
daysOfYears+=366 if yearfun(i) else 365
daysOfYears+=daysOfMonths
weak=1+daysOfYears%7
print "Sun\tMon\tTue\tWed\tThu\tFri\tSat"
print "\t"*weak,
for i in range(1,daysOfMonth+1):
weak+=1
if weak%7!=0:
print i,'\t',
else:
print i,'\n',

if __name__=='__main__':
simpleCalendar()
 
python中怎查詢method 的功可以?

查詢用help
>>>help(obj.method) #通用查詢方法 對象名obj.方法名method

本例
>>>help("".method) #""為空白字串,但已經是一個string對象了
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.